44require "ldclient-rb/impl/data_store"
55require "ldclient-rb/impl/diagnostic_events"
66require "ldclient-rb/impl/evaluator"
7+ require "ldclient-rb/impl/evaluation_with_hook_result"
78require "ldclient-rb/impl/flag_tracker"
89require "ldclient-rb/impl/store_client_wrapper"
910require "ldclient-rb/impl/migrations/tracker"
@@ -217,8 +218,13 @@ def initialized?
217218 # @return the variation for the provided context, or the default value if there's an error
218219 #
219220 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
222228 end
223229
224230 #
@@ -246,11 +252,12 @@ def variation(key, context, default)
246252 #
247253 def variation_detail ( key , context , default )
248254 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 )
251258 end
252259
253- detail
260+ result . evaluation_detail
254261 end
255262
256263 #
@@ -270,15 +277,17 @@ def variation_detail(key, context, default)
270277 # @param method [Symbol]
271278 # @param &block [#call] Implicit passed block
272279 #
280+ # @return [LaunchDarkly::Impl::EvaluationWithHookResult]
281+ #
273282 private def evaluate_with_hooks ( key , context , default , method )
274283 return yield if @hooks . empty?
275284
276285 hooks , evaluation_series_context = prepare_hooks ( key , context , default , method )
277286 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 )
280289
281- [ evaluation_detail , flag , error ]
290+ evaluation_result
282291 end
283292
284293 #
@@ -375,20 +384,24 @@ def migration_variation(key, context, default_stage)
375384 end
376385
377386 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
379392
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
382397
383- if Migrations :: VALID_STAGES . include? ( stage )
398+ detail = LaunchDarkly :: Impl :: Evaluator . error_result ( LaunchDarkly :: EvaluationReason :: ERROR_WRONG_TYPE , default_stage . to_s )
384399 tracker = Impl ::Migrations ::OpTracker . new ( @config . logger , key , flag , context , detail , default_stage )
385- return stage , tracker
386- end
387400
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
390403
391- [ default_stage , tracker ]
404+ [ result . results [ :stage ] , result . results [ : tracker] ]
392405 end
393406
394407 #
@@ -628,16 +641,13 @@ def create_default_data_source(sdk_key, config, diagnostic_accumulator)
628641
629642 #
630643 # @param key [String]
631- # @param context [Hash, LDContext]
644+ # @param context [LDContext]
632645 # @param default [Object]
633646 #
634647 # @return [Array<EvaluationDetail, [LaunchDarkly::Impl::Model::FeatureFlag, nil], [String, nil]>]
635648 #
636649 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 )
641651 end
642652
643653 #
0 commit comments