Class: ChankoAb::Logic::Base
- Inherits:
-
Object
- Object
- ChankoAb::Logic::Base
show all
- Defined in:
- lib/chanko_ab/logic/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(split_test, caller_scope, request, identifier, using_index) ⇒ Base
Returns a new instance of Base.
4
5
6
7
8
9
10
11
|
# File 'lib/chanko_ab/logic/base.rb', line 4
def initialize(split_test, caller_scope, request, identifier, using_index)
@split_test = split_test
@caller_scope = caller_scope
@request = request
@identifier = identifier
@using_index = using_index || 0
@data = {}
end
|
Instance Method Details
#ab_index ⇒ Object
30
31
32
|
# File 'lib/chanko_ab/logic/base.rb', line 30
def ab_index
assigned_number % split_size
end
|
#data(name, &block) ⇒ Object
13
14
15
|
# File 'lib/chanko_ab/logic/base.rb', line 13
def data(name, &block)
@data[name] ||= block.call
end
|
#fetch(key) ⇒ Object
50
51
52
|
# File 'lib/chanko_ab/logic/base.rb', line 50
def fetch(key)
item[1][key]
end
|
#item ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/chanko_ab/logic/base.rb', line 63
def item
if Rails.env.test? && ChankoAb::Test.overwritten?(@split_test.unit)
return pattern_by_overwritten
else
index = decide_pattern_index
return nil if index > patterns.size
return patterns[index]
end
end
|
#just_pattern_sizes ⇒ Object
17
18
19
|
# File 'lib/chanko_ab/logic/base.rb', line 17
def just_pattern_sizes
raise NotImplementedError
end
|
#log(template_name) ⇒ Object
59
60
61
|
# File 'lib/chanko_ab/logic/base.rb', line 59
def log(template_name)
ChankoAb.log(@caller_scope, log_key(template_name), request: @request, identifier: @identifier)
end
|
#log_key(template_name) ⇒ Object
54
55
56
57
|
# File 'lib/chanko_ab/logic/base.rb', line 54
def log_key(template_name)
template = @split_test.fetch_template(template_name)
template.gsub('[name]', name)
end
|
#name ⇒ Object
46
47
48
|
# File 'lib/chanko_ab/logic/base.rb', line 46
def name
item[0]
end
|
#should_run_default? ⇒ Boolean
34
35
36
37
|
# File 'lib/chanko_ab/logic/base.rb', line 34
def should_run_default?
return true if !item
@identifier.blank?
end
|
#validate! ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/chanko_ab/logic/base.rb', line 21
def validate!
unless Rails.env.production?
raise "Argument should be a divisor of #{just_patterns_size.max}, but #{split_size} is given." if !just_patterns_size.member?(split_size)
raise "Identifier is blank" if @identifier.blank?
raise "Identifier is too short" if @identifier.size < (@using_index + 1)
raise 'Too large pattern size' if patterns.size >= just_pattern_sizes.max
end
end
|