verdict 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDEzN2VlY2MyNGUyZmQ0MzY2YWViYTQ5NmRjMmVhZjUzMmFjZDNlYg==
4
+ ZDNjZTFjMmI3OTZlMDQyOTlkYTdjYzU5ZmNhZjMxYjcxODVhYmZmMQ==
5
5
  data.tar.gz: !binary |-
6
- YmVlMzgxMDAxZDRjOGI2NmI0MzY2OTNkYzkxOGY2Y2VmNjFkM2EyMg==
6
+ MGU5YWNkZDY2YmIzNjhmZDAwNjFkODIzZGI0MGRmZjMwMWEwYzFlZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzJhMDlmYTRiMjI4NTRiZDI5ZGM4YWY2MTNkNTQxNzFiYjZkZDdkNGE1MmJm
10
- NDdjZTEzMWU1NTBmNDllNDJhODRhYTcxYTNiYTgwOTI2NjA5ZmIyYTVlN2E1
11
- ZjZjNzVkZGQyNTBlNGFiNDYzYmI2YTFjOWU4MDRmZWQzMjk2MjE=
9
+ MDI2ZDI3OTVhYjljZjU1Y2NiNDAyMWMwYTIyMTU1NTgwZGNhNTEzNWI0Nzdl
10
+ ZWYwNGM2MDA1ODE3ZWE5ZjFkOGZlZmI5MWRkY2IxOTI2ZDQ4MzZjNTA4N2Ex
11
+ MmYxZmNhMmYzOGM3Y2FkNTFiMDhmMTQ1ZjUwMzBjZjE2ZTViMGU=
12
12
  data.tar.gz: !binary |-
13
- MGZmYTI3ODA4ZGMzMzhlMTM4ZThlYWZkMGU3NWE3YWYzZmY4NzY2ZDk0OGQ2
14
- ZDEyYTUzN2VhYmU4MTdlNjRlY2M4OWI1MmJlOWMwNmZhMDRkMzg0OWQ2NGE1
15
- ZGEwMmY3ODFjNDUwNjdlNGZmMDM4NmUyOWRjMmRlZGFiMjM4NTQ=
13
+ YTYxYTM4NGMxNjUwOWUyM2ZkYjI2NTZhOTFmOGRlYjMzMWQ1ZjU4YmIzOTUy
14
+ ZDQ2OTA0ZjNmZmY1OWJjMWVlOTI3NjliNzFmNmRkZjBkYzQ3NjNhNDIyODE1
15
+ NjQxYmM0YjI3MGE1MTc0N2E4NWQ2MjczMDRhYmM0N2I1YTAxZDk=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Verdict
1
+ # Verdict [![Build Status](https://travis-ci.org/Shopify/verdict.png)](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 `Experiments::Experiment` model used create the experiment instance,
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 `Experiments::Experiment`
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 Experiments['my experiment'].switch(shop, context)
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
- `Experiment::Assignment` instance. By default it will use `subject.id.to_s` as
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 `Experiments.logger`. The Railtie
79
- sets `Experiment.logger` to `Rails.logger`, so experiment assignments will show
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
 
@@ -14,12 +14,14 @@ class Verdict::Experiment
14
14
  @handle = handle.to_s
15
15
 
16
16
  options = default_options.merge(options)
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]
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)
@@ -1,3 +1,3 @@
1
1
  module Verdict
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest