determinator 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ccc82084d2734ddf50ebb5900f73b9e985bd05f
4
- data.tar.gz: 1b231a0fc9228692f357a2db213a170c046fb92e
3
+ metadata.gz: 17f714ab0a57974a7934bdcf86631e65e4e5111d
4
+ data.tar.gz: 82caf2b07f4a891cc2621fc1ef72aa8c569347b1
5
5
  SHA512:
6
- metadata.gz: 968a15520388364e962099c8d762431c38a7ff21825263352f506ace9ee568f03564e2aa5428d9ede53c46a33a2d7c3e482da4339d9503ecaf890b7cdf18a850
7
- data.tar.gz: fbe0fface76305e3348c76647f34272df03a0fde293db796d565db8fe3e615c7ebcfd743288d783e7c2892c3847afed85e849b35ca987cb10ada1d24121174d4
6
+ metadata.gz: 37b01ffc666efd680e085365b61b4516cf3c5300e7b215e98e0dde2e1472ea494f7fc5748f811420f137452ee163ed86488f47360205631cc825e2c896780948
7
+ data.tar.gz: d974d0c38bf2f3963dfa4661252e9bd41b5ef5d5d11ee3e91a2a85658254ca96d90ec5ae8c1d7b5e332065e7254bd0ff79db4cdb7a091a04a76b2e8094f7fd4a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.12.1 (2018-02-01)
2
+
3
+ Bug Fix:
4
+ - Allow `.for_actor` calls when using `RSpec::Determinator` to test code that uses determinator. (#44)
5
+
1
6
  # v0.12.0 (2018-01-23)
2
7
 
3
8
  Feature:
data/README.md CHANGED
@@ -16,24 +16,38 @@ A gem that works with _Florence_ to deterministically calculate whether an **act
16
16
 
17
17
  For Deliveroo Employees:
18
18
 
19
- - Many people contribute to Determinator and Florence. We hang out in [this Slack channel](slack://channel?team=T03EUNC3F&id=C7437816J)
19
+ - Many people contribute to Determinator and Florence. We hang out in [this Slack channel](https://deliveroo.slack.com/app_redirect?channel=florence_wg)
20
20
  - [This JIRA board](https://deliveroo.atlassian.net/secure/RapidBoard.jspa?rapidView=156) covers pieces of work that are planned or in-flight
21
21
  - [This Workplace group](https://deliveroo.facebook.com/groups/1893254264328414/) holds more general discussions about the Florence ecosystem
22
22
 
23
23
  At the moment we can only promise support for Determinator within Deliveroo, but if you add [issues to this github repo](https://github.com/deliveroo/determinator/issues) we'll try and help if we can!
24
24
 
25
- ## Usage
25
+ ## Basic Use
26
26
 
27
- Once [set up](#installation), determinator can be used to determine whether a **feature flag** or **experiment** is on or off for the current user and, for experiments, which **variant** they should see.
27
+ Once [set up](#installation), determinator can be used to determine whether a **feature flag** or **experiment** is on or off for the current actor (or user) and, for experiments, which **variant** they should see.
28
28
 
29
29
  ```ruby
30
- # Feature flags
30
+ # Feature flags: the basics
31
+ Determinator.instance.feature_flag_on?(:my_feature_name, id: 'some user')
32
+ # => true
33
+ Determinator.instance.feature_flag_on?(:my_feature_name, id: 'another user')
34
+ # => false
35
+
36
+ # A handy short cut…
37
+ def determinator
38
+ # See the urther Usage section below for a handy shorthand which means ID
39
+ # and GUID don't need to be specified every time you need a determination.
40
+ end
41
+
42
+ # Which means you can also do:
31
43
  if determinator.feature_flag_on?(:my_feature_name)
32
44
  # Show the feature
33
45
  end
34
46
 
35
47
  # Experiments
36
48
  case determinator.which_variant(:my_experiment_name)
49
+ when false
50
+ # This actor isn't in a target group for this experiment
37
51
  when 'control'
38
52
  # Do nothing different
39
53
  when 'sloths'
@@ -43,7 +57,9 @@ when 'velociraptors'
43
57
  end
44
58
  ```
45
59
 
46
- Feature flags and experiments can be targeted to specific actors by specifying actor properties (which must match the constraints defined in the feature).
60
+ Please note that Determinator requires an identifier for your actor either an ID (when they are logged in, eg. a user id), or a globally unique id (GUID) that identifies them across sessions (which would normally be storied in a cookie or in a long-lived session store).
61
+
62
+ Feature flags and experiments can be limited to actors with specific properties by specifying them when (which must match the constraints defined in the feature).
47
63
 
48
64
  ```ruby
49
65
  # Targeting specific actors
@@ -59,13 +75,9 @@ Writing tests? Check out the [Local development](docs/local_development.md) docs
59
75
 
60
76
  ## Installation
61
77
 
62
- Determinator requires your application to be subscribed to the a `features` topic via Routemaster.
63
-
64
- The drain must expire the routemaster cache on receipt of events, `Routemaster::Drain::CacheBusting.new` or better.
65
-
66
- Check the example Rails app in `examples` for more information on how to make use of this gem.
78
+ Determinator requires a initialiser block somewhere in your application's boot process, it might look something like this:
67
79
 
68
- ```
80
+ ```ruby
69
81
  # config/initializers/determinator.rb
70
82
 
71
83
  require 'determinator/retrieve/routemaster'
@@ -79,38 +91,90 @@ Determinator.configure(
79
91
  )
80
92
  ```
81
93
 
82
- ### Using Determinator in RSpec
94
+ This configures the `Determinator.instance` with:
95
+
96
+ - What **retrieval** mechanism should be used to get feature details
97
+ - (optional) How **errors** should be reported
98
+ - (optional) How **missing features** should be monitored (as they indicate something's up with your code or your set up!)
83
99
 
84
- * Include those lines in `spec_helper.rb`.
100
+ You may also want to configure a `determinator` helper method inside your web request scope, see below for more information.
85
101
 
102
+ ## Further Usage
86
103
 
104
+ Once this is done you can ask for a determination like this:
105
+
106
+ ```ruby
107
+ # Anywhere in your application:
108
+ variant = Determinator.instance.which_variant?(
109
+ :my_experiment_name,
110
+ id: 123,
111
+ guid: 'anonymous id',
112
+ properties: {
113
+ employee: true,
114
+ using_top_level_domain: 'uk'
115
+ }
116
+ )
87
117
  ```
88
- require 'rspec/determinator'
89
118
 
90
- Determinator.configure(retrieval: nil)
119
+ Or, if you're within a web request, you might want to use a shorthand, and let determinator remember the ID, GUID and any properties which will be true. The following will have the same effect:
91
120
 
121
+ ```ruby
122
+ # Somewhere inside your request's scope:
123
+ def determinator
124
+ @determinator ||= Determinator.instance.for_actor(
125
+ id: 123,
126
+ guid: 'anonymous id',
127
+ default_properties: {
128
+ employee: true,
129
+ using_top_level_domain: 'uk'
130
+ }
131
+ )
132
+ end
133
+
134
+ # Anywhere in your requests' scope:
135
+ determinator.which_variant(:my_experiment_name)
92
136
  ```
93
137
 
94
- * Tag your rspec test with `:determinator_support`, so `forced_determination` helper method will be available.
138
+ Check the example Rails app in the `examples` directory for more information on how to make use of this gem.
139
+
140
+ ### Routemaster
141
+
142
+ Determinator's [Routemaster](https://github.com/deliveroo/routemaster) integration requires your application to be subscribed to the a `features` topic.
143
+
144
+ The drain must expire the routemaster cache on receipt of events, making use of `Routemaster::Drain::CacheBusting.new` or similar is recommended.
145
+
146
+ ### Using Determinator in RSpec
147
+
148
+ * Include the `spec_helper.rb`.
95
149
 
150
+ ```ruby
151
+ require 'rspec/determinator'
96
152
 
153
+ Determinator.configure(retrieval: nil)
97
154
  ```
98
155
 
156
+ * Tag your rspec test with `:determinator_support`, so the `forced_determination` helper method will be available.
157
+
158
+ ```ruby
99
159
  RSpec.describe "something", :determinator_support do
100
160
 
101
161
  context "something" do
102
162
  forced_determination(:my_feature_flag, true)
103
163
  forced_determination(:my_experiment, "variant_a")
164
+ forced_determination(:my_lazyexperiment, :some_lazy_variable)
165
+ let(:some_lazy_variable) { 'variant_b' }
104
166
 
105
167
  it "uses forced_determination" do
106
168
  expect(Determinator.instance.feature_flag_on?(:my_feature_flag)).to eq(true)
107
169
  expect(Determinator.instance.which_variant(:my_experiment)).to eq("variant_a")
170
+ expect(Determinator.instance.which_variant(:my_lazy_experiment)).to eq("variant_b")
108
171
  end
109
172
  end
110
173
  end
111
-
112
174
  ```
113
175
 
176
+ * Check out [the specs for `RSpec::Determinator`](spec/rspec/determinator_spec.rb) to find out what you can do!
177
+
114
178
  ### Retrieval Cache
115
179
 
116
180
  Determinator will function fully without a retrieval_cache set, although Determinator will produce 1 Redis query for every determination. By setting a `retrieval_cache` as an instance of `ActiveSupport::Cache::MemoryStore` (or equivalent) this can be reduced per application instance. This cache is not expired so *must* have a `expires_in` set, ideally to a short amount of time.
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = '0.12.0'
2
+ VERSION = '0.12.1'
3
3
  end
@@ -40,6 +40,10 @@ module RSpec
40
40
  @mocked_results = Hash.new { |h, k| h[k] = {} }
41
41
  end
42
42
 
43
+ def for_actor(**args)
44
+ ::Determinator::ActorControl.new(self, **args)
45
+ end
46
+
43
47
  def mock_result(name, result, only_for: {})
44
48
  @mocked_results[name.to_s][only_for] = result
45
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: routemaster-drain