@@ -120,6 +120,9 @@ class EvaluationReason
120120 # or deleted. If {#kind} is not {#RULE_MATCH}, this will be `nil`.
121121 attr_reader :rule_id
122122
123+ # A boolean or nil value representing if the rule or fallthrough has an experiment rollout.
124+ attr_reader :in_experiment
125+
123126 # The key of the prerequisite flag that did not return the desired variation. If {#kind} is not
124127 # {#PREREQUISITE_FAILED}, this will be `nil`.
125128 attr_reader :prerequisite_key
@@ -136,8 +139,12 @@ def self.off
136139
137140 # Returns an instance whose {#kind} is {#FALLTHROUGH}.
138141 # @return [EvaluationReason]
139- def self . fallthrough
140- @@fallthrough
142+ def self . fallthrough ( in_experiment = false )
143+ if in_experiment
144+ @@fallthrough_with_experiment
145+ else
146+ @@fallthrough
147+ end
141148 end
142149
143150 # Returns an instance whose {#kind} is {#TARGET_MATCH}.
@@ -153,10 +160,16 @@ def self.target_match
153160 # @param rule_id [String] unique string identifier for the matched rule
154161 # @return [EvaluationReason]
155162 # @raise [ArgumentError] if `rule_index` is not a number or `rule_id` is not a string
156- def self . rule_match ( rule_index , rule_id )
163+ def self . rule_match ( rule_index , rule_id , in_experiment = false )
157164 raise ArgumentError . new ( "rule_index must be a number" ) if !( rule_index . is_a? Numeric )
158165 raise ArgumentError . new ( "rule_id must be a string" ) if !rule_id . nil? && !( rule_id . is_a? String ) # in test data, ID could be nil
159- new ( :RULE_MATCH , rule_index , rule_id , nil , nil )
166+
167+ if in_experiment
168+ er = new ( :RULE_MATCH , rule_index , rule_id , nil , nil , true )
169+ else
170+ er = new ( :RULE_MATCH , rule_index , rule_id , nil , nil )
171+ end
172+ er
160173 end
161174
162175 # Returns an instance whose {#kind} is {#PREREQUISITE_FAILED}.
@@ -204,11 +217,17 @@ def to_s
204217 def inspect
205218 case @kind
206219 when :RULE_MATCH
207- "RULE_MATCH(#{ @rule_index } ,#{ @rule_id } )"
220+ if @in_experiment
221+ "RULE_MATCH(#{ @rule_index } ,#{ @rule_id } ,#{ @in_experiment } )"
222+ else
223+ "RULE_MATCH(#{ @rule_index } ,#{ @rule_id } )"
224+ end
208225 when :PREREQUISITE_FAILED
209226 "PREREQUISITE_FAILED(#{ @prerequisite_key } )"
210227 when :ERROR
211228 "ERROR(#{ @error_kind } )"
229+ when :FALLTHROUGH
230+ @in_experiment ? "FALLTHROUGH(#{ @in_experiment } )" : @kind . to_s
212231 else
213232 @kind . to_s
214233 end
@@ -225,11 +244,21 @@ def as_json(*) # parameter is unused, but may be passed if we're using the json
225244 # as_json and then modify the result.
226245 case @kind
227246 when :RULE_MATCH
228- { kind : @kind , ruleIndex : @rule_index , ruleId : @rule_id }
247+ if @in_experiment
248+ { kind : @kind , ruleIndex : @rule_index , ruleId : @rule_id , inExperiment : @in_experiment }
249+ else
250+ { kind : @kind , ruleIndex : @rule_index , ruleId : @rule_id }
251+ end
229252 when :PREREQUISITE_FAILED
230253 { kind : @kind , prerequisiteKey : @prerequisite_key }
231254 when :ERROR
232255 { kind : @kind , errorKind : @error_kind }
256+ when :FALLTHROUGH
257+ if @in_experiment
258+ { kind : @kind , inExperiment : @in_experiment }
259+ else
260+ { kind : @kind }
261+ end
233262 else
234263 { kind : @kind }
235264 end
@@ -263,14 +292,15 @@ def [](key)
263292
264293 private
265294
266- def initialize ( kind , rule_index , rule_id , prerequisite_key , error_kind )
295+ def initialize ( kind , rule_index , rule_id , prerequisite_key , error_kind , in_experiment = nil )
267296 @kind = kind . to_sym
268297 @rule_index = rule_index
269298 @rule_id = rule_id
270299 @rule_id . freeze if !rule_id . nil?
271300 @prerequisite_key = prerequisite_key
272301 @prerequisite_key . freeze if !prerequisite_key . nil?
273302 @error_kind = error_kind
303+ @in_experiment = in_experiment
274304 end
275305
276306 private_class_method :new
@@ -279,6 +309,7 @@ def self.make_error(error_kind)
279309 new ( :ERROR , nil , nil , nil , error_kind )
280310 end
281311
312+ @@fallthrough_with_experiment = new ( :FALLTHROUGH , nil , nil , nil , nil , true )
282313 @@fallthrough = new ( :FALLTHROUGH , nil , nil , nil , nil )
283314 @@off = new ( :OFF , nil , nil , nil , nil )
284315 @@target_match = new ( :TARGET_MATCH , nil , nil , nil , nil )
0 commit comments