@@ -199,13 +199,20 @@ def decide(user_context, key, decide_options = [])
199
199
experiment = nil
200
200
decision_source = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
201
201
202
- decision , reasons_received = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes , decide_options )
202
+ variation , reasons_received = user_context . find_validated_forced_decision ( key , nil )
203
203
reasons . push ( *reasons_received )
204
204
205
+ if variation
206
+ decision = Optimizely ::DecisionService ::Decision . new ( nil , variation , Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ] )
207
+ else
208
+ decision , reasons_received = @decision_service . get_variation_for_feature ( config , feature_flag , user_context , decide_options )
209
+ reasons . push ( *reasons_received )
210
+ end
211
+
205
212
# Send impression event if Decision came from a feature test and decide options doesn't include disableDecisionEvent
206
213
if decision . is_a? ( Optimizely ::DecisionService ::Decision )
207
214
experiment = decision . experiment
208
- rule_key = experiment [ 'key' ]
215
+ rule_key = experiment ? experiment [ 'key' ] : nil
209
216
variation = decision [ 'variation' ]
210
217
variation_key = variation [ 'key' ]
211
218
feature_enabled = variation [ 'featureEnabled' ]
@@ -291,6 +298,10 @@ def decide_for_keys(user_context, keys, decide_options = [])
291
298
decisions
292
299
end
293
300
301
+ def get_flag_variation_by_key ( flag_key , variation_key )
302
+ project_config . get_variation_from_flag ( flag_key , variation_key )
303
+ end
304
+
294
305
# Buckets visitor and sends impression event to Optimizely.
295
306
#
296
307
# @param experiment_key - Experiment which needs to be activated.
@@ -490,7 +501,8 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
490
501
return false
491
502
end
492
503
493
- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
504
+ user_context = create_user_context ( user_id , attributes )
505
+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
494
506
495
507
feature_enabled = false
496
508
source_string = Optimizely ::DecisionService ::DECISION_SOURCES [ 'ROLLOUT' ]
@@ -739,7 +751,8 @@ def get_all_feature_variables(feature_flag_key, user_id, attributes = nil)
739
751
return nil
740
752
end
741
753
742
- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
754
+ user_context = create_user_context ( user_id , attributes )
755
+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
743
756
variation = decision ? decision [ 'variation' ] : nil
744
757
feature_enabled = variation ? variation [ 'featureEnabled' ] : false
745
758
all_variables = { }
@@ -881,7 +894,8 @@ def get_variation_with_config(experiment_key, user_id, attributes, config)
881
894
882
895
return nil unless user_inputs_valid? ( attributes )
883
896
884
- variation_id , = @decision_service . get_variation ( config , experiment_id , user_id , attributes )
897
+ user_context = create_user_context ( user_id , attributes )
898
+ variation_id , = @decision_service . get_variation ( config , experiment_id , user_context )
885
899
variation = config . get_variation_from_id ( experiment_key , variation_id ) unless variation_id . nil?
886
900
variation_key = variation [ 'key' ] if variation
887
901
decision_notification_type = if config . feature_experiment? ( experiment_id )
@@ -947,7 +961,8 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
947
961
return nil
948
962
end
949
963
950
- decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_id , attributes )
964
+ user_context = create_user_context ( user_id , attributes )
965
+ decision , = @decision_service . get_variation_for_feature ( config , feature_flag , user_context )
951
966
variation = decision ? decision [ 'variation' ] : nil
952
967
feature_enabled = variation ? variation [ 'featureEnabled' ] : false
953
968
@@ -1083,8 +1098,12 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
1083
1098
experiment_id = experiment [ 'id' ]
1084
1099
experiment_key = experiment [ 'key' ]
1085
1100
1086
- variation_id = ''
1087
- variation_id = config . get_variation_id_from_key_by_experiment_id ( experiment_id , variation_key ) if experiment_id != ''
1101
+ if experiment_id != ''
1102
+ variation_id = config . get_variation_id_from_key_by_experiment_id ( experiment_id , variation_key )
1103
+ else
1104
+ varaition = get_flag_variation_by_key ( flag_key , variation_key )
1105
+ variation_id = varaition ? varaition [ 'id' ] : ''
1106
+ end
1088
1107
1089
1108
metadata = {
1090
1109
flag_key : flag_key ,
0 commit comments