@@ -120,6 +120,9 @@ class EvaluationReason
120
120
# or deleted. If {#kind} is not {#RULE_MATCH}, this will be `nil`.
121
121
attr_reader :rule_id
122
122
123
+ # A boolean or nil value representing if the rule or fallthrough has an experiment rollout.
124
+ attr_reader :in_experiment
125
+
123
126
# The key of the prerequisite flag that did not return the desired variation. If {#kind} is not
124
127
# {#PREREQUISITE_FAILED}, this will be `nil`.
125
128
attr_reader :prerequisite_key
@@ -136,8 +139,12 @@ def self.off
136
139
137
140
# Returns an instance whose {#kind} is {#FALLTHROUGH}.
138
141
# @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
141
148
end
142
149
143
150
# Returns an instance whose {#kind} is {#TARGET_MATCH}.
@@ -153,10 +160,16 @@ def self.target_match
153
160
# @param rule_id [String] unique string identifier for the matched rule
154
161
# @return [EvaluationReason]
155
162
# @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 )
157
164
raise ArgumentError . new ( "rule_index must be a number" ) if !( rule_index . is_a? Numeric )
158
165
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
160
173
end
161
174
162
175
# Returns an instance whose {#kind} is {#PREREQUISITE_FAILED}.
@@ -204,11 +217,17 @@ def to_s
204
217
def inspect
205
218
case @kind
206
219
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
208
225
when :PREREQUISITE_FAILED
209
226
"PREREQUISITE_FAILED(#{ @prerequisite_key } )"
210
227
when :ERROR
211
228
"ERROR(#{ @error_kind } )"
229
+ when :FALLTHROUGH
230
+ @in_experiment ? "FALLTHROUGH(#{ @in_experiment } )" : @kind . to_s
212
231
else
213
232
@kind . to_s
214
233
end
@@ -225,11 +244,21 @@ def as_json(*) # parameter is unused, but may be passed if we're using the json
225
244
# as_json and then modify the result.
226
245
case @kind
227
246
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
229
252
when :PREREQUISITE_FAILED
230
253
{ kind : @kind , prerequisiteKey : @prerequisite_key }
231
254
when :ERROR
232
255
{ 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
233
262
else
234
263
{ kind : @kind }
235
264
end
@@ -263,14 +292,15 @@ def [](key)
263
292
264
293
private
265
294
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 )
267
296
@kind = kind . to_sym
268
297
@rule_index = rule_index
269
298
@rule_id = rule_id
270
299
@rule_id . freeze if !rule_id . nil?
271
300
@prerequisite_key = prerequisite_key
272
301
@prerequisite_key . freeze if !prerequisite_key . nil?
273
302
@error_kind = error_kind
303
+ @in_experiment = in_experiment
274
304
end
275
305
276
306
private_class_method :new
@@ -279,6 +309,7 @@ def self.make_error(error_kind)
279
309
new ( :ERROR , nil , nil , nil , error_kind )
280
310
end
281
311
312
+ @@fallthrough_with_experiment = new ( :FALLTHROUGH , nil , nil , nil , nil , true )
282
313
@@fallthrough = new ( :FALLTHROUGH , nil , nil , nil , nil )
283
314
@@off = new ( :OFF , nil , nil , nil , nil )
284
315
@@target_match = new ( :TARGET_MATCH , nil , nil , nil , nil )
0 commit comments