Module: ABPlugin
- Defined in:
- lib/a_b_plugin.rb,
lib/a_b_plugin/api.rb,
lib/a_b_plugin/helper.rb,
lib/a_b_plugin/adapters/rails.rb,
lib/a_b_plugin/adapters/sinatra.rb
Defined Under Namespace
Modules: Adapters, Helper
Classes: API
Class Method Summary
collapse
Class Method Details
.config(token, url) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/a_b_plugin.rb', line 19
def config(token, url)
API.base_uri @@url
@@api = API.new token
boot = @@api.boot
@@tests = boot['tests']
@@token = token
@@url = url
@@user_token = boot['user_token']
end
|
.select_variant?(selections, variant) ⇒ Boolean
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/a_b_plugin.rb', line 29
def select_variant?(selections, variant)
test = test_from_variant(variant)
return false unless test
if !selections || !selections[test['name']]
variants = test['variants'].sort do |a, b|
a['visitors'] <=> b['visitors']
end
variants.first['visitors'] += 1
selections[test['name']] = variants.first['name']
end
selections[test['name']] == variant
end
|
.test_from_variant(variant) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/a_b_plugin.rb', line 42
def test_from_variant(variant)
return nil unless ABPlugin.tests
tests = ABPlugin.tests.select do |t|
t['variants'].collect { |v| v['name'] }.include?(variant)
end
tests.first
end
|