lib/split/trial.rb in split-1.4.2 vs lib/split/trial.rb in split-1.4.3

- old
+ new

@@ -39,12 +39,11 @@ alternative.increment_completion else Array(goals).each {|g| alternative.increment_completion(g) } end - context.send(Split.configuration.on_trial_complete, self) \ - if Split.configuration.on_trial_complete && context + run_callback context, Split.configuration.on_trial_complete end end # Choose an alternative, add a participant, and save the alternative choice on the user. This # method is guaranteed to only run once, and will skip the alternative choosing process if run @@ -52,11 +51,11 @@ def choose!(context = nil) @user.cleanup_old_experiments # Only run the process once return alternative if @alternative_choosen - if @options[:override] + if override_is_alternative? self.alternative = @options[:override] elsif @options[:disabled] || Split.configuration.disabled? self.alternative = @experiment.control elsif @experiment.has_winner? self.alternative = @experiment.winner @@ -71,21 +70,28 @@ self.alternative = @experiment.next_alternative # Increment the number of participants since we are actually choosing a new alternative self.alternative.increment_participation - # Run the post-choosing hook on the context - context.send(Split.configuration.on_trial_choose, self) \ - if Split.configuration.on_trial_choose && context + run_callback context, Split.configuration.on_trial_choose end end @user[@experiment.key] = alternative.name if should_store_alternative? @alternative_choosen = true + run_callback context, Split.configuration.on_trial unless @options[:disabled] || Split.configuration.disabled? alternative end private + + def run_callback(context, callback_name) + context.send(callback_name, self) if callback_name && context.respond_to?(callback_name, true) + end + + def override_is_alternative? + @experiment.alternatives.map(&:name).include?(@options[:override]) + end def should_store_alternative? if @options[:override] || @options[:disabled] Split.configuration.store_override else