@@ -164,7 +164,7 @@ def get_variation_for_feature(project_config, feature_flag, user_context, decide
164
164
# feature_flag - The feature flag the user wants to access
165
165
# user_context - Optimizely user context instance
166
166
#
167
- # Returns Decision struct (nil if the user is not bucketed into any of the experiments on the feature)
167
+ # Returns DecisionResult struct.
168
168
get_variations_for_feature_list ( project_config , [ feature_flag ] , user_context , decide_options ) . first
169
169
end
170
170
@@ -178,7 +178,7 @@ def get_variations_for_feature_list(project_config, feature_flags, user_context,
178
178
# decide_options: Decide options.
179
179
#
180
180
# Returns:
181
- # Array of Decision struct.
181
+ # Array of DecisionResult struct.
182
182
ignore_ups = decide_options . include? Optimizely ::Decide ::OptimizelyDecideOption ::IGNORE_USER_PROFILE_SERVICE
183
183
user_profile_tracker = nil
184
184
unless ignore_ups && @user_profile_service
@@ -187,18 +187,10 @@ def get_variations_for_feature_list(project_config, feature_flags, user_context,
187
187
end
188
188
decisions = [ ]
189
189
feature_flags . each do |feature_flag |
190
- decide_reasons = [ ]
191
190
# check if the feature is being experiment on and whether the user is bucketed into the experiment
192
- decision , reasons_received = get_variation_for_feature_experiment ( project_config , feature_flag , user_context , user_profile_tracker , decide_options )
193
- decide_reasons . push ( *reasons_received )
194
- if decision
195
- decisions << [ decision , decide_reasons ]
196
- else
197
- # Proceed to rollout if the decision is nil
198
- rollout_decision , reasons_received = get_variation_for_feature_rollout ( project_config , feature_flag , user_context )
199
- decide_reasons . push ( *reasons_received )
200
- decisions << [ rollout_decision , decide_reasons ]
201
- end
191
+ decision_result = get_variation_for_feature_experiment ( project_config , feature_flag , user_context , user_profile_tracker , decide_options )
192
+ decision_result = get_variation_for_feature_rollout ( project_config , feature_flag , user_context ) unless decision_result . decision
193
+ decisions << decision_result
202
194
end
203
195
user_profile_tracker &.save_user_profile
204
196
decisions
@@ -211,8 +203,8 @@ def get_variation_for_feature_experiment(project_config, feature_flag, user_cont
211
203
# feature_flag - The feature flag the user wants to access
212
204
# user_context - Optimizely user context instance
213
205
#
214
- # Returns Decision struct (nil if the user is not bucketed into any of the experiments on the feature)
215
- # or nil if the user is not bucketed into any of the experiments on the feature
206
+ # Returns a DecisionResult containing the decision (or nil if not bucketed),
207
+ # an error flag, and an array of decision reasons.
216
208
decide_reasons = [ ]
217
209
user_id = user_context . user_id
218
210
feature_flag_key = feature_flag [ 'key' ]
@@ -265,7 +257,8 @@ def get_variation_for_feature_rollout(project_config, feature_flag, user_context
265
257
# feature_flag - The feature flag the user wants to access
266
258
# user_context - Optimizely user context instance
267
259
#
268
- # Returns the Decision struct or nil if not bucketed into any of the targeting rules
260
+ # Returns a DecisionResult containing the decision (or nil if not bucketed),
261
+ # an error flag, and an array of decision reasons.
269
262
decide_reasons = [ ]
270
263
271
264
rollout_id = feature_flag [ 'rolloutId' ]
@@ -274,18 +267,18 @@ def get_variation_for_feature_rollout(project_config, feature_flag, user_context
274
267
message = "Feature flag '#{ feature_flag_key } ' is not used in a rollout."
275
268
@logger . log ( Logger ::DEBUG , message )
276
269
decide_reasons . push ( message )
277
- return nil , decide_reasons
270
+ return DecisionResult . new ( nil , false , decide_reasons )
278
271
end
279
272
280
273
rollout = project_config . get_rollout_from_id ( rollout_id )
281
274
if rollout . nil?
282
275
message = "Rollout with ID '#{ rollout_id } ' is not in the datafile '#{ feature_flag [ 'key' ] } '"
283
276
@logger . log ( Logger ::DEBUG , message )
284
277
decide_reasons . push ( message )
285
- return nil , decide_reasons
278
+ return DecisionResult . new ( nil , false , decide_reasons )
286
279
end
287
280
288
- return nil , decide_reasons if rollout [ 'experiments' ] . empty?
281
+ return DecisionResult . new ( nil , false , decide_reasons ) if rollout [ 'experiments' ] . empty?
289
282
290
283
index = 0
291
284
rollout_rules = rollout [ 'experiments' ]
@@ -294,14 +287,14 @@ def get_variation_for_feature_rollout(project_config, feature_flag, user_context
294
287
decide_reasons . push ( *reasons_received )
295
288
if variation
296
289
rule = rollout_rules [ index ]
297
- feature_decision = Decision . new ( rule , variation , DECISION_SOURCES [ 'ROLLOUT' ] )
298
- return [ feature_decision , decide_reasons ]
290
+ feature_decision = Decision . new ( rule , variation , DECISION_SOURCES [ 'ROLLOUT' ] , nil )
291
+ return DecisionResult . new ( feature_decision , false , decide_reasons )
299
292
end
300
293
301
294
index = skip_to_everyone_else ? ( rollout_rules . length - 1 ) : ( index + 1 )
302
295
end
303
296
304
- [ nil , decide_reasons ]
297
+ DecisionResult . new ( nil , false , decide_reasons )
305
298
end
306
299
307
300
def get_variation_from_experiment_rule ( project_config , flag_key , rule , user , user_profile_tracker , options = [ ] )
0 commit comments