Module: ABTester
- Defined in:
- lib/ab_tester.rb
Defined Under Namespace
Modules: ClassMethods
Classes: ChoiceOptions, Railtie
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/ab_tester.rb', line 43
def self.included(base)
base.send :extend, ABTester::ClassMethods
base.send :protected, :ab_choice
base.send :helper_method, :choose
base.send :helper_method, :identity_hash
base.send :helper_method, :find_or_create_choice
end
|
Instance Method Details
#ab_choice(selected_choice_value, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/ab_tester.rb', line 23
def ab_choice(selected_choice_value, &block)
@ab_choice ||= find_or_create_choice
if @ab_choice.choice == selected_choice_value.to_s
yield
else
nil
end
end
|
#choose(selected_choice_value) ⇒ Object
19
20
21
|
# File 'lib/ab_tester.rb', line 19
def choose(selected_choice_value)
@selected_choice_value = selected_choice_value
end
|
#find_or_create_choice(choice_value = self.class.ab_options.shuffle) ⇒ Object
13
14
15
16
17
|
# File 'lib/ab_tester.rb', line 13
def find_or_create_choice(choice_value = self.class.ab_options.shuffle)
ab_choice = ABChoice.find_or_create_by_identity_hash identity_hash
ab_choice.update_attribute(:choice, @selected_choice_value || choice_value) unless ab_choice.choice
ab_choice
end
|