Class: Hackle::Decider
- Inherits:
-
Object
- Object
- Hackle::Decider
- Defined in:
- lib/hackle/decision/decider.rb
Instance Method Summary collapse
- #decide(experiment:, user_id:) ⇒ Object
- #decide_running(running_experiment:, user_id:) ⇒ Object
-
#initialize ⇒ Decider
constructor
A new instance of Decider.
Constructor Details
Instance Method Details
#decide(experiment:, user_id:) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/hackle/decision/decider.rb', line 30 def decide(experiment:, user_id:) case experiment when Experiment::Completed Decision::ForcedAllocated.new(variation_key: experiment.winner_variation_key) when Experiment::Running decide_running(running_experiment: experiment, user_id: user_id) end end |
#decide_running(running_experiment:, user_id:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hackle/decision/decider.rb', line 39 def decide_running(running_experiment:, user_id:) overridden_variation = running_experiment.get_overridden_variation(user_id: user_id) return Decision::ForcedAllocated.new(variation_key: overridden_variation.key) unless overridden_variation.nil? allocated_slot = @bucketer.bucketing(bucket: running_experiment.bucket, user_id: user_id) return Decision::NotAllocated.new if allocated_slot.nil? allocated_variation = running_experiment.get_variation(variation_id: allocated_slot.variation_id) return Decision::NotAllocated.new if allocated_variation.nil? return Decision::NotAllocated.new if allocated_variation.dropped Decision::NaturalAllocated.new(variation: allocated_variation) end |