Method: Conductor::Weights.find_or_create
- Defined in:
- lib/conductor/weights.rb
.find_or_create(group_name, alternatives) ⇒ Object
Returns all the weights for a given group. In the event that the alternatives specified for the group do not match all the alternatives previously computed for the group, new weights are generated. The cache is used to speed up this check
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/conductor/weights.rb', line 8 def find_or_create(group_name, alternatives) weights_for_group = Conductor.cache.read("Conductor::Experiment::#{Conductor.attribute_for_weighting}::#{group_name}::Alternatives") alternatives_array = weights_for_group.map(&:alternative).sort if weights_for_group if alternatives_array.eql?(alternatives.sort) Conductor.log('alternatives equal to cache') return weights_for_group else Conductor.log('alternatives NOT equal to cache. Need to recompute') compute(group_name, alternatives) # get the new weights weights_for_group = Conductor::Experiment::Weight.find(:all, :conditions => "group_name = '#{group_name}'") Conductor.cache.delete("Conductor::Experiment::#{Conductor.attribute_for_weighting}::#{group_name}::Alternatives") Conductor.cache.write("Conductor::Experiment::#{Conductor.attribute_for_weighting}::#{group_name}::Alternatives", weights_for_group) return weights_for_group end end |