Module: Modesty::ExperimentMethods
- Included in:
- API
- Defined in:
- lib/modesty/experiment.rb
Instance Method Summary collapse
- #add_experiment(exp) ⇒ Object
- #decide_identity(options) ⇒ Object
- #experiment(sym, options = {}, &blk) ⇒ Object
- #experiments ⇒ Object
- #group(sym, options = {}) ⇒ Object
- #group?(sym, options = {}) ⇒ Boolean
- #new_experiment(slug) {|Experiment::Builder.new(exp)| ... } ⇒ Object
Instance Method Details
#add_experiment(exp) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/modesty/experiment.rb', line 15 def add_experiment(exp) raise Experiment::Error, <<-msg if self.experiments.include? exp.slug Experiment #{exp.slug.inspect} already defined! msg self.experiments[exp.slug] = exp end |
#decide_identity(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/modesty/experiment.rb', line 35 def decide_identity() if .include? :identity [:identity] elsif .include? :for [:for] elsif .include? :on [:on] else Modesty.identity end end |
#experiment(sym, options = {}, &blk) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/modesty/experiment.rb', line 47 def experiment(sym, ={}, &blk) exp = self.experiments[sym] identity = decide_identity() interface = Experiment::Interface.new(exp, identity) self.with_identity identity do yield interface end interface.last_value end |
#experiments ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/modesty/experiment.rb', line 7 def experiments @experiments ||= Hash.new do |h, k| raise Experiment::Error, <<-msg.squish Unrecognized experiment #{k.inspect}. msg end end |
#group(sym, options = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/modesty/experiment.rb', line 70 def group(sym, ={}) id = decide_identity() exp = self.experiments[sym] exp ? exp.group(id) : :control end |
#group?(sym, options = {}) ⇒ Boolean
60 61 62 63 64 65 66 67 68 |
# File 'lib/modesty/experiment.rb', line 60 def group?(sym, ={}) id = decide_identity() exp = sym.to_s.split(/\//) alt = exp.pop.to_sym exp = exp.join('/').to_sym exp = self.experiments[exp] exp.group? alt end |
#new_experiment(slug) {|Experiment::Builder.new(exp)| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/modesty/experiment.rb', line 22 def new_experiment(slug, &block) exp = Experiment.new(slug) yield Experiment::Builder.new(exp) if block exp.metrics.each do |m| m.experiments << exp exp.alternatives.each do |a| Modesty.new_metric(m.slug/exp.slug/a, :parent => m, :experiment => exp) end end add_experiment(exp) exp end |