4
4
require "ldclient-rb/impl/data_store"
5
5
require "ldclient-rb/impl/diagnostic_events"
6
6
require "ldclient-rb/impl/evaluator"
7
+ require "ldclient-rb/impl/evaluation_with_hook_result"
7
8
require "ldclient-rb/impl/flag_tracker"
8
9
require "ldclient-rb/impl/store_client_wrapper"
9
10
require "ldclient-rb/impl/migrations/tracker"
@@ -217,8 +218,13 @@ def initialized?
217
218
# @return the variation for the provided context, or the default value if there's an error
218
219
#
219
220
def variation ( key , context , default )
220
- detail , _ , _ , = variation_with_flag ( key , context , default )
221
- detail . value
221
+ context = Impl ::Context ::make_context ( context )
222
+ result = evaluate_with_hooks ( key , context , default , :variation ) do
223
+ detail , _ , _ = variation_with_flag ( key , context , default )
224
+ LaunchDarkly ::Impl ::EvaluationWithHookResult . new ( detail )
225
+ end
226
+
227
+ result . evaluation_detail . value
222
228
end
223
229
224
230
#
@@ -246,11 +252,12 @@ def variation(key, context, default)
246
252
#
247
253
def variation_detail ( key , context , default )
248
254
context = Impl ::Context ::make_context ( context )
249
- detail , _ , _ = evaluate_with_hooks ( key , context , default , :variation_detail ) do
250
- evaluate_internal ( key , context , default , true )
255
+ result = evaluate_with_hooks ( key , context , default , :variation_detail ) do
256
+ detail , _ , _ = evaluate_internal ( key , context , default , true )
257
+ LaunchDarkly ::Impl ::EvaluationWithHookResult . new ( detail )
251
258
end
252
259
253
- detail
260
+ result . evaluation_detail
254
261
end
255
262
256
263
#
@@ -270,15 +277,17 @@ def variation_detail(key, context, default)
270
277
# @param method [Symbol]
271
278
# @param &block [#call] Implicit passed block
272
279
#
280
+ # @return [LaunchDarkly::Impl::EvaluationWithHookResult]
281
+ #
273
282
private def evaluate_with_hooks ( key , context , default , method )
274
283
return yield if @hooks . empty?
275
284
276
285
hooks , evaluation_series_context = prepare_hooks ( key , context , default , method )
277
286
hook_data = execute_before_evaluation ( hooks , evaluation_series_context )
278
- evaluation_detail , flag , error = yield
279
- execute_after_evaluation ( hooks , evaluation_series_context , hook_data , evaluation_detail )
287
+ evaluation_result = yield
288
+ execute_after_evaluation ( hooks , evaluation_series_context , hook_data , evaluation_result . evaluation_detail )
280
289
281
- [ evaluation_detail , flag , error ]
290
+ evaluation_result
282
291
end
283
292
284
293
#
@@ -375,20 +384,24 @@ def migration_variation(key, context, default_stage)
375
384
end
376
385
377
386
context = Impl ::Context ::make_context ( context )
378
- detail , flag , _ = variation_with_flag ( key , context , default_stage . to_s )
387
+ result = evaluate_with_hooks ( key , context , default_stage , :migration_variation ) do
388
+ detail , flag , _ = variation_with_flag ( key , context , default_stage . to_s )
389
+
390
+ stage = detail . value
391
+ stage = stage . to_sym if stage . respond_to? :to_sym
379
392
380
- stage = detail . value
381
- stage = stage . to_sym if stage . respond_to? :to_sym
393
+ if Migrations ::VALID_STAGES . include? ( stage )
394
+ tracker = Impl ::Migrations ::OpTracker . new ( @config . logger , key , flag , context , detail , default_stage )
395
+ next LaunchDarkly ::Impl ::EvaluationWithHookResult . new ( detail , { stage : stage , tracker : tracker } )
396
+ end
382
397
383
- if Migrations :: VALID_STAGES . include? ( stage )
398
+ detail = LaunchDarkly :: Impl :: Evaluator . error_result ( LaunchDarkly :: EvaluationReason :: ERROR_WRONG_TYPE , default_stage . to_s )
384
399
tracker = Impl ::Migrations ::OpTracker . new ( @config . logger , key , flag , context , detail , default_stage )
385
- return stage , tracker
386
- end
387
400
388
- detail = LaunchDarkly ::Impl ::Evaluator . error_result ( LaunchDarkly :: EvaluationReason :: ERROR_WRONG_TYPE , default_stage . to_s )
389
- tracker = Impl :: Migrations :: OpTracker . new ( @config . logger , key , flag , context , detail , default_stage )
401
+ LaunchDarkly ::Impl ::EvaluationWithHookResult . new ( detail , { stage : default_stage , tracker : tracker } )
402
+ end
390
403
391
- [ default_stage , tracker ]
404
+ [ result . results [ :stage ] , result . results [ : tracker] ]
392
405
end
393
406
394
407
#
@@ -628,16 +641,13 @@ def create_default_data_source(sdk_key, config, diagnostic_accumulator)
628
641
629
642
#
630
643
# @param key [String]
631
- # @param context [Hash, LDContext]
644
+ # @param context [LDContext]
632
645
# @param default [Object]
633
646
#
634
647
# @return [Array<EvaluationDetail, [LaunchDarkly::Impl::Model::FeatureFlag, nil], [String, nil]>]
635
648
#
636
649
def variation_with_flag ( key , context , default )
637
- context = Impl ::Context ::make_context ( context )
638
- evaluate_with_hooks ( key , context , default , :variation_detail ) do
639
- evaluate_internal ( key , context , default , false )
640
- end
650
+ evaluate_internal ( key , context , default , false )
641
651
end
642
652
643
653
#
0 commit comments