verdict 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +7 -7
- data/lib/verdict/experiment.rb +20 -6
- data/lib/verdict/version.rb +1 -1
- data/test/experiment_test.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDNjZTFjMmI3OTZlMDQyOTlkYTdjYzU5ZmNhZjMxYjcxODVhYmZmMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGU5YWNkZDY2YmIzNjhmZDAwNjFkODIzZGI0MGRmZjMwMWEwYzFlZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDI2ZDI3OTVhYjljZjU1Y2NiNDAyMWMwYTIyMTU1NTgwZGNhNTEzNWI0Nzdl
|
10
|
+
ZWYwNGM2MDA1ODE3ZWE5ZjFkOGZlZmI5MWRkY2IxOTI2ZDQ4MzZjNTA4N2Ex
|
11
|
+
MmYxZmNhMmYzOGM3Y2FkNTFiMDhmMTQ1ZjUwMzBjZjE2ZTViMGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTYxYTM4NGMxNjUwOWUyM2ZkYjI2NTZhOTFmOGRlYjMzMWQ1ZjU4YmIzOTUy
|
14
|
+
ZDQ2OTA0ZjNmZmY1OWJjMWVlOTI3NjliNzFmNmRkZjBkYzQ3NjNhNDIyODE1
|
15
|
+
NjQxYmM0YjI3MGE1MTc0N2E4NWQ2MjczMDRhYmM0N2I1YTAxZDk=
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Verdict
|
1
|
+
# Verdict [](https://travis-ci.org/Shopify/verdict)
|
2
2
|
|
3
3
|
This library allows you to define and use experiments in your application.
|
4
4
|
|
@@ -17,7 +17,7 @@ Add this line to your application's Gemfile, and run `bundle install`:
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
This gem contains the `
|
20
|
+
This gem contains the `Verdict::Experiment` model used create the experiment instance,
|
21
21
|
in order consistently modify application behaviour based on an object's unique key.
|
22
22
|
|
23
23
|
Define an experiment like so:
|
@@ -40,7 +40,7 @@ end
|
|
40
40
|
```
|
41
41
|
|
42
42
|
Usually you want to place this in a file called **my_experiment.rb** in the
|
43
|
-
**/app/experiments** folder. Also, usually you want to subclass `
|
43
|
+
**/app/experiments** folder. Also, usually you want to subclass `Verdict::Experiment`
|
44
44
|
to set some default options for your app's environment, and call `define` on that class
|
45
45
|
instead.
|
46
46
|
|
@@ -48,7 +48,7 @@ Refer to the experiment elsewhere in your codebase like this:
|
|
48
48
|
|
49
49
|
``` ruby
|
50
50
|
context = { ... } # anything you want to pass along to the qualify block.
|
51
|
-
case
|
51
|
+
case Verdict['my experiment'].switch(shop, context)
|
52
52
|
when :test
|
53
53
|
# Handle test group
|
54
54
|
when :control
|
@@ -71,12 +71,12 @@ an object that responds to the following tho methods:
|
|
71
71
|
|
72
72
|
In which `experiment` is the Experiment instance, `subject_identifier` is a
|
73
73
|
string that uniquely identifies the subject, and `assignment` is an
|
74
|
-
`
|
74
|
+
`Verdict::Assignment` instance. By default it will use `subject.id.to_s` as
|
75
75
|
`subject_identifier`, but you can change that by overriding the
|
76
76
|
`def subject_identifier(subject)` method on the experiment.
|
77
77
|
|
78
|
-
The library will also log every assignment to `
|
79
|
-
sets `
|
78
|
+
The library will also log every assignment to `Verdict.logger`. The Railtie
|
79
|
+
sets `Verdict.logger` to `Rails.logger`, so experiment assignments will show
|
80
80
|
up in your Rails log. You can override the logging by overriding the
|
81
81
|
`def log_assignment(assignment)` method on the experiment.
|
82
82
|
|
data/lib/verdict/experiment.rb
CHANGED
@@ -14,12 +14,14 @@ class Verdict::Experiment
|
|
14
14
|
@handle = handle.to_s
|
15
15
|
|
16
16
|
options = default_options.merge(options)
|
17
|
-
@qualifier
|
18
|
-
@event_logger
|
19
|
-
@subject_storage
|
20
|
-
@store_unqualified
|
21
|
-
@segmenter
|
22
|
-
@subject_type
|
17
|
+
@qualifier = options[:qualifier]
|
18
|
+
@event_logger = options[:event_logger] || Verdict::EventLogger.new(Verdict.default_logger)
|
19
|
+
@subject_storage = options[:storage] || Verdict::Storage::MemoryStorage.new
|
20
|
+
@store_unqualified = options[:store_unqualified]
|
21
|
+
@segmenter = options[:segmenter]
|
22
|
+
@subject_type = options[:subject_type]
|
23
|
+
@disqualify_empty_identifier = options[:disqualify_empty_identifier]
|
24
|
+
|
23
25
|
instance_eval(&block) if block_given?
|
24
26
|
end
|
25
27
|
|
@@ -83,6 +85,8 @@ class Verdict::Experiment
|
|
83
85
|
conversion = subject_conversion(identifier, goal)
|
84
86
|
event_logger.log_conversion(conversion)
|
85
87
|
conversion
|
88
|
+
rescue Verdict::EmptySubjectIdentifier
|
89
|
+
raise unless disqualify_empty_identifier?
|
86
90
|
end
|
87
91
|
|
88
92
|
def assign(subject, context = nil)
|
@@ -96,6 +100,16 @@ class Verdict::Experiment
|
|
96
100
|
store_assignment(assignment)
|
97
101
|
rescue Verdict::StorageError
|
98
102
|
subject_assignment(identifier, nil, nil)
|
103
|
+
rescue Verdict::EmptySubjectIdentifier
|
104
|
+
if disqualify_empty_identifier?
|
105
|
+
subject_assignment(identifier, nil, nil)
|
106
|
+
else
|
107
|
+
raise
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def disqualify_empty_identifier?
|
112
|
+
@disqualify_empty_identifier
|
99
113
|
end
|
100
114
|
|
101
115
|
def disqualify(subject)
|
data/lib/verdict/version.rb
CHANGED
data/test/experiment_test.rb
CHANGED
@@ -37,6 +37,18 @@ class ExperimentTest < MiniTest::Unit::TestCase
|
|
37
37
|
assert_equal nil, non_qualified.group
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_disqualify_empty_identifier
|
41
|
+
e = Verdict::Experiment.new('test', disqualify_empty_identifier: true) do
|
42
|
+
groups do
|
43
|
+
group :a, :half
|
44
|
+
group :b, :rest
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
assert !e.assign(nil).qualified?
|
49
|
+
assert_equal nil, e.convert('', :mygoal)
|
50
|
+
end
|
51
|
+
|
40
52
|
def test_assignment
|
41
53
|
e = Verdict::Experiment.new('test') do
|
42
54
|
qualify { |subject| subject <= 2 }
|
@@ -46,6 +58,8 @@ class ExperimentTest < MiniTest::Unit::TestCase
|
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
61
|
+
assert_raises(Verdict::EmptySubjectIdentifier) { e.assign(nil) }
|
62
|
+
|
49
63
|
assignment = e.assign(1)
|
50
64
|
assert_kind_of Verdict::Assignment, assignment
|
51
65
|
assert assignment.qualified?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verdict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|