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