lib/split/trial.rb in split-4.0.1 vs lib/split/trial.rb in split-4.0.2

- old
+ new

@@ -22,28 +22,28 @@ @metadata ||= experiment.metadata[alternative.name] if experiment.metadata end def alternative @alternative ||= if @experiment.has_winner? - @experiment.winner - end + @experiment.winner + end end def alternative=(alternative) @alternative = if alternative.kind_of?(Split::Alternative) alternative else - @experiment.alternatives.find{|a| a.name == alternative } + @experiment.alternatives.find { |a| a.name == alternative } end end def complete!(context = nil) if alternative if Array(goals).empty? alternative.increment_completion else - Array(goals).each {|g| alternative.increment_completion(g) } + Array(goals).each { |g| alternative.increment_completion(g) } end run_callback context, Split.configuration.on_trial_complete end end @@ -95,33 +95,32 @@ run_callback context, Split.configuration.on_trial unless @options[:disabled] || Split.configuration.disabled? || new_participant_and_cohorting_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 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 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 - !exclude_user? + def should_store_alternative? + if @options[:override] || @options[:disabled] + Split.configuration.store_override + else + !exclude_user? + end end - end - def cleanup_old_versions - if @experiment.version > 0 - @user.cleanup_old_versions!(@experiment) + def cleanup_old_versions + if @experiment.version > 0 + @user.cleanup_old_versions!(@experiment) + end end - end - def exclude_user? - @options[:exclude] || @experiment.start_time.nil? || @user.max_experiments_reached?(@experiment.key) - end + def exclude_user? + @options[:exclude] || @experiment.start_time.nil? || @user.max_experiments_reached?(@experiment.key) + end end end