class Ab::Tests
Public Class Methods
after_picking_variant(&block)
click to toggle source
# File lib/ab/tests.rb, line 8 def after_picking_variant(&block) AssignedTest.after_picking_variant(&block) end
before_picking_variant(&block)
click to toggle source
# File lib/ab/tests.rb, line 4 def before_picking_variant(&block) AssignedTest.before_picking_variant(&block) end
new(json, id)
click to toggle source
# File lib/ab/tests.rb, line 13 def initialize(json, id) json ||= {} config = json.is_a?(Hash) ? json : JSON.parse(json) @ab_tests = config['ab_tests'] || [] @salt = config['salt'] @bucket_count = config['bucket_count'] @id = id end
Public Instance Methods
all()
click to toggle source
# File lib/ab/tests.rb, line 22 def all grouped_ab_tests.keys.map { |name| [name, assigned_test(name).variant(false)] }.to_h end
method_missing(name, *)
click to toggle source
# File lib/ab/tests.rb, line 26 def method_missing(name, *) assigned_test(name.to_s) || null_test end
respond_to_missing?(*)
click to toggle source
# File lib/ab/tests.rb, line 30 def respond_to_missing?(*) true end
Private Instance Methods
assigned_test(name)
click to toggle source
# File lib/ab/tests.rb, line 40 def assigned_test(name) @assigned_tests ||= {} if grouped_ab_tests.key?(name) @assigned_tests[name] ||= begin test = Test.new(grouped_ab_tests[name], @salt, @bucket_count) AssignedTest.new(test, @id) end end end
grouped_ab_tests()
click to toggle source
# File lib/ab/tests.rb, line 50 def grouped_ab_tests @grouped_ab_tests ||= @ab_tests.reduce({}) do |hash, test| hash[test['name']] = test hash end end
null_test()
click to toggle source
# File lib/ab/tests.rb, line 36 def null_test @null_test ||= NullTest.new end