Class: Ab::Tests

Inherits:
Object
  • Object
show all
Defined in:
lib/ab/tests.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, id) ⇒ Tests

Returns a new instance of Tests.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ab/tests.rb', line 13

def initialize(json, id)
  json ||= {}
  config = json.is_a?(Hash) ? json : JSON.parse(json)

  salt = config['salt']
  bucket_count = config['bucket_count']

  tests = (config['ab_tests'] || []).map { |test| Test.new(test, salt, bucket_count) }

  @assigned_tests = tests.map do |test|
    assigned_test = AssignedTest.new(test, id)
    define_singleton_method(test.name) { assigned_test }
    [test.name, assigned_test]
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



33
34
35
# File 'lib/ab/tests.rb', line 33

def method_missing(*)
  @null_test ||= NullTest.new
end

Class Method Details

.after_picking_variant(&block) ⇒ Object



8
9
10
# File 'lib/ab/tests.rb', line 8

def after_picking_variant(&block)
  AssignedTest.after_picking_variant(&block)
end

.before_picking_variant(&block) ⇒ Object



4
5
6
# File 'lib/ab/tests.rb', line 4

def before_picking_variant(&block)
  AssignedTest.before_picking_variant(&block)
end

Instance Method Details

#allObject



29
30
31
# File 'lib/ab/tests.rb', line 29

def all
  Hash[@assigned_tests.map { |name, assigned_test| [name, assigned_test.variant(false)] }]
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ab/tests.rb', line 37

def respond_to_missing?(*)
  true
end