split 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.mdown +6 -0
- data/README.mdown +13 -1
- data/lib/split/helper.rb +20 -21
- data/lib/split/version.rb +1 -1
- data/spec/helper_spec.rb +9 -3
- metadata +18 -18
data/CHANGELOG.mdown
CHANGED
data/README.mdown
CHANGED
@@ -167,8 +167,20 @@ You can override the default configuration options of Split like so:
|
|
167
167
|
Split.configure do |config|
|
168
168
|
config.robot_regex = /my_custom_robot_regex/
|
169
169
|
config.ignore_ip_addresses << '81.19.48.130'
|
170
|
+
config.db_failover = true # handle redis errors gracefully
|
171
|
+
config.db_failover_on_db_error = proc{|error| Rails.logger.error(error.message) }
|
170
172
|
end
|
171
173
|
|
174
|
+
### DB failover solution
|
175
|
+
|
176
|
+
Due to the fact that Redis has no autom. failover mechanism, it's
|
177
|
+
possible to switch on the `db_failover` config option, so that `ab_test`
|
178
|
+
and `finished` will not crash in case of a db failure. `ab_test` always
|
179
|
+
delivers alternative A (the first one) in that case.
|
180
|
+
|
181
|
+
It's also possible to set a `db_failover_on_db_error` callback (proc)
|
182
|
+
for example to log these errors via Rails.logger.
|
183
|
+
|
172
184
|
### Redis
|
173
185
|
|
174
186
|
You may want to change the Redis host and port Split connects to, or
|
@@ -251,4 +263,4 @@ Tests can be ran with `rake spec`
|
|
251
263
|
|
252
264
|
## Copyright
|
253
265
|
|
254
|
-
Copyright (c) 2012 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/split/blob/master/LICENSE) for details.
|
266
|
+
Copyright (c) 2012 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/split/blob/master/LICENSE) for details.
|
data/lib/split/helper.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
module Split
|
2
2
|
module Helper
|
3
3
|
def ab_test(experiment_name, *alternatives)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if forced_alternative = override(experiment.name, alternatives)
|
9
|
-
ret = forced_alternative
|
4
|
+
begin
|
5
|
+
experiment = Split::Experiment.find_or_create(experiment_name, *alternatives)
|
6
|
+
if experiment.winner
|
7
|
+
ret = experiment.winner.name
|
10
8
|
else
|
11
|
-
|
12
|
-
|
13
|
-
if ab_user[experiment.key]
|
14
|
-
ret = ab_user[experiment.key]
|
9
|
+
if forced_alternative = override(experiment.name, alternatives)
|
10
|
+
ret = forced_alternative
|
15
11
|
else
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
begin_experiment(experiment, experiment.control.name) if exclude_visitor?
|
13
|
+
|
14
|
+
if ab_user[experiment.key]
|
15
|
+
ret = ab_user[experiment.key]
|
16
|
+
else
|
17
|
+
alternative = experiment.next_alternative
|
18
|
+
alternative.increment_participation
|
19
|
+
begin_experiment(experiment, alternative.name)
|
20
|
+
ret = alternative.name
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
24
|
+
rescue Errno::ECONNREFUSED => e
|
25
|
+
raise unless Split.configuration.db_failover
|
26
|
+
Split.configuration.db_failover_on_db_error.call(e)
|
27
|
+
ret = Hash === (a0 = alternatives.first) ? a0.keys.first : a0
|
22
28
|
end
|
23
|
-
|
24
29
|
if block_given?
|
25
30
|
if defined?(capture) # a block in a rails view
|
26
31
|
block = Proc.new { yield(ret) }
|
@@ -32,12 +37,6 @@ module Split
|
|
32
37
|
else
|
33
38
|
ret
|
34
39
|
end
|
35
|
-
rescue Errno::ECONNREFUSED => e
|
36
|
-
raise unless Split.configuration.db_failover
|
37
|
-
Split.configuration.db_failover_on_db_error.call(e)
|
38
|
-
ret = Hash === (a0 = alternatives.first) ? a0.keys.first : a0
|
39
|
-
yield(ret) if block_given?
|
40
|
-
ret
|
41
40
|
end
|
42
41
|
|
43
42
|
def finished(experiment_name, options = {:reset => true})
|
data/lib/split/version.rb
CHANGED
data/spec/helper_spec.rb
CHANGED
@@ -281,6 +281,12 @@ describe Split::Helper do
|
|
281
281
|
|
282
282
|
context 'and db_failover config option is turned off' do
|
283
283
|
|
284
|
+
before(:each) do
|
285
|
+
Split.configure do |config|
|
286
|
+
config.db_failover = false
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
284
290
|
describe 'ab_test' do
|
285
291
|
it 'should raise an exception' do
|
286
292
|
lambda {
|
@@ -327,9 +333,9 @@ describe Split::Helper do
|
|
327
333
|
ab_test('link_color', 'blue', 'red').should eq('blue')
|
328
334
|
ab_test('link_color', 'blue' => 0.01, 'red' => 0.2).should eq('blue')
|
329
335
|
ab_test('link_color', {'blue' => 0.8}, {'red' => 20}).should eq('blue')
|
330
|
-
ab_test('link_color', 'blue', 'red') do |
|
331
|
-
|
332
|
-
end
|
336
|
+
ab_test('link_color', 'blue', 'red') do |alternative|
|
337
|
+
"shared/#{alternative}"
|
338
|
+
end.should eq('shared/blue')
|
333
339
|
end
|
334
340
|
end
|
335
341
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70173932070820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70173932070820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: redis-namespace
|
27
|
-
requirement: &
|
27
|
+
requirement: &70173932070060 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70173932070060
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra
|
38
|
-
requirement: &
|
38
|
+
requirement: &70173932069160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.2.6
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70173932069160
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70173932068040 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70173932068040
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70173932066460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70173932066460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70173932065340 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.6'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70173932065340
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rack-test
|
82
|
-
requirement: &
|
82
|
+
requirement: &70173932064500 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.6'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70173932064500
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: guard-rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70173932062500 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0.4'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70173932062500
|
102
102
|
description:
|
103
103
|
email:
|
104
104
|
- andrewnez@gmail.com
|