lib/split/trial.rb in split-1.1.0 vs lib/split/trial.rb in split-1.2.0

- old
+ new

@@ -1,19 +1,25 @@ module Split class Trial attr_accessor :experiment + attr_accessor :metadata def initialize(attrs = {}) self.experiment = attrs.delete(:experiment) self.alternative = attrs.delete(:alternative) + self.metadata = attrs.delete(:metadata) @user = attrs.delete(:user) @options = attrs @alternative_choosen = false end + def metadata + @metadata ||= experiment.metadata[alternative.name] + end + def alternative @alternative ||= if @experiment.has_winner? @experiment.winner end end @@ -24,17 +30,15 @@ else @experiment.alternatives.find{|a| a.name == alternative } end end - def complete!(goals, context = nil) - goals = goals || [] - + def complete!(goals=[], context = nil) if alternative - if goals.empty? + if Array(goals).empty? alternative.increment_completion else - goals.each {|g| alternative.increment_completion(g) } + Array(goals).each {|g| alternative.increment_completion(g) } end context.send(Split.configuration.on_trial_complete, self) \ if Split.configuration.on_trial_complete && context end