Class: Hackle::Decider
- Inherits:
-
Object
- Object
- Hackle::Decider
- Defined in:
- lib/hackle/decision/decider.rb
Instance Method Summary collapse
- #decide(experiment:, user:) ⇒ Decision
- #decide_running(running_experiment:, user:) ⇒ Decision
-
#initialize ⇒ Decider
constructor
A new instance of Decider.
Constructor Details
Instance Method Details
#decide(experiment:, user:) ⇒ Decision
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hackle/decision/decider.rb', line 39 def decide(experiment:, user:) case experiment when Experiment::Completed Decision::ForcedAllocated.new(variation_key: experiment.winner_variation_key) when Experiment::Running decide_running(running_experiment: experiment, user: user) else NotAllocated.new end end |
#decide_running(running_experiment:, user:) ⇒ Decision
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hackle/decision/decider.rb', line 54 def decide_running(running_experiment:, user:) overridden_variation = running_experiment.get_overridden_variation(user: user) return Decision::ForcedAllocated.new(variation_key: overridden_variation.key) unless overridden_variation.nil? allocated_slot = @bucketer.bucketing(bucket: running_experiment.bucket, user: user) 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 |