arturo 2.3.0 → 2.4.0
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 +4 -4
- data/README.md +113 -84
- data/lib/arturo/feature_availability.rb +1 -1
- data/lib/arturo/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a02a4e7e0db51f26446e2c7b0c1cf52074b7e248
|
4
|
+
data.tar.gz: ec2c34461ec09ff68eade07571b9f9e556236b87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1502b91de3d23c5f6611a968fc8e83b25a08f3fcd5fdf1263875e24d312c1ee01933833520fc29bf7e61cc26168c6f3671091458ac0b5bc3d26d4945c5f0bee
|
7
|
+
data.tar.gz: 570c22bb590cedb2661546a782946db45f0b62027218cefdd30d9246112e217091a9978e00bb86f65a637396ed5d3cc479788d06b56729857f2487033817498d
|
data/README.md
CHANGED
@@ -7,11 +7,8 @@ but offers more fine-grained control. It supports deploying features only for
|
|
7
7
|
a given percent* of your users and whitelisting and blacklisting users based
|
8
8
|
on any criteria you can express in Ruby.
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
user will still have it on Tuesday (unless, of course, you *decrease*
|
13
|
-
the feature's deployment percentage or change its white- or blacklist
|
14
|
-
settings).
|
10
|
+
The selection is deterministic. So if a user has a feature on Monday, the
|
11
|
+
user will still have it on Tuesday (unless, you *decrease* feature's deployment percentage or change its white- or blacklist settings).
|
15
12
|
|
16
13
|
### A quick example
|
17
14
|
|
@@ -19,38 +16,44 @@ Trish, a developer is working on a new feature: a live feed of recent postings
|
|
19
16
|
in the user's city that shows up in the user's sidebar. First, she uses Arturo's
|
20
17
|
view helpers to control who sees the sidebar widget:
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
</
|
29
|
-
|
19
|
+
```ERB
|
20
|
+
<%# in app/views/layout/_sidebar.html.erb: %>
|
21
|
+
<% if_feature_enabled(:live_postings) do %>
|
22
|
+
<div class='widget'>
|
23
|
+
<h3>Recent Postings</h3>
|
24
|
+
<ol id='live_postings'>
|
25
|
+
</ol>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
```
|
30
29
|
|
31
30
|
Then Trish writes some Javascript that will poll the server for recent
|
32
31
|
postings and put them in the sidebar widget:
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
```js
|
34
|
+
// in public/javascript/live_postings.js:
|
35
|
+
$(function() {
|
36
|
+
var livePostingsList = $('#live_postings');
|
37
|
+
if (livePostingsList.length > 0) {
|
38
|
+
var updatePostingsList = function() {
|
39
|
+
livePostingsList.load('/listings/recent');
|
40
|
+
setTimeout(updatePostingsList, 30);
|
41
|
+
}
|
42
|
+
updatePostingsList();
|
43
|
+
}
|
44
|
+
});
|
45
|
+
````
|
45
46
|
|
46
47
|
Trish uses Arturo's Controller filters to control who has access to
|
47
48
|
the feature:
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
```Ruby
|
51
|
+
# in app/controllers/postings_controller:
|
52
|
+
class PostingsController < ApplicationController
|
53
|
+
require_feature :live_postings, only: :recent
|
54
|
+
# ...
|
55
|
+
end
|
56
|
+
```
|
54
57
|
|
55
58
|
Trish then deploys this code to production. Nobody will see the feature yet,
|
56
59
|
since it's not on for anyone. (In fact, the feature doesn't yet exist
|
@@ -66,18 +69,10 @@ feature and deploy it to all users.
|
|
66
69
|
|
67
70
|
## Installation
|
68
71
|
|
69
|
-
### In Rails 3 or 4, with Bundler
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
$ gem install arturo --version="~> 1.0"
|
76
|
-
|
77
|
-
### In Rails 2.3
|
78
|
-
|
79
|
-
Rails 2.3 is no longer supported and has been archived on the
|
80
|
-
[`rails_2_3` branch](http://github.com/jamesarosen/arturo/tree/rails_2_3).
|
73
|
+
```Ruby
|
74
|
+
gem 'arturo', '~> 1.0'
|
75
|
+
```
|
81
76
|
|
82
77
|
## Configuration
|
83
78
|
|
@@ -85,14 +80,18 @@ Rails 2.3 is no longer supported and has been archived on the
|
|
85
80
|
|
86
81
|
#### Run the generators:
|
87
82
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
```
|
84
|
+
rails g arturo:migration
|
85
|
+
rails g arturo:initializer
|
86
|
+
rails g arturo:routes
|
87
|
+
rails g arturo:assets
|
88
|
+
```
|
92
89
|
|
93
90
|
#### Run the migration:
|
94
91
|
|
95
|
-
|
92
|
+
```
|
93
|
+
rake db:migrate
|
94
|
+
```
|
96
95
|
|
97
96
|
#### Edit the generated migration as necessary
|
98
97
|
|
@@ -134,15 +133,19 @@ the context of a Controller or View instance. It should return `true` if
|
|
134
133
|
and only if the current user may manage permissions. The default implementation
|
135
134
|
is as follows:
|
136
135
|
|
137
|
-
|
136
|
+
```Ruby
|
137
|
+
current_user.present? && current_user.admin?
|
138
|
+
```
|
138
139
|
|
139
140
|
You can change the implementation in
|
140
141
|
`config/initializers/arturo_initializer.rb`. A reasonable implementation
|
141
142
|
might be
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
144
|
+
```Ruby
|
145
|
+
Arturo.permit_management do
|
146
|
+
signed_in? && current_user.can?(:manage_features)
|
147
|
+
end
|
148
|
+
```
|
146
149
|
|
147
150
|
### <span id='featurerecipients'>Feature Recipients</span>
|
148
151
|
|
@@ -163,15 +166,19 @@ The default implementation simply returns `current_user`. Like
|
|
163
166
|
in `config/initializers/arturo_initializer.rb`. If you want to deploy features
|
164
167
|
on a per-account basis, a reasonable implementation might be
|
165
168
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
+
```Ruby
|
170
|
+
Arturo.feature_recipient do
|
171
|
+
current_account
|
172
|
+
end
|
173
|
+
```
|
169
174
|
|
170
175
|
or
|
171
176
|
|
172
|
-
|
173
|
-
|
174
|
-
|
177
|
+
```Ruby
|
178
|
+
Arturo.feature_recipient do
|
179
|
+
current_user.account
|
180
|
+
end
|
181
|
+
```
|
175
182
|
|
176
183
|
If the block returns `nil`, the feature will be disabled.
|
177
184
|
|
@@ -182,24 +189,30 @@ will have a feature. For example, if all premium users should have the
|
|
182
189
|
`:awesome` feature, place the following in
|
183
190
|
`config/initializers/arturo_initializer.rb`:
|
184
191
|
|
185
|
-
|
186
|
-
|
187
|
-
|
192
|
+
```Ruby
|
193
|
+
Arturo::Feature.whitelist(:awesome) do |user|
|
194
|
+
user.account.premium?
|
195
|
+
end
|
196
|
+
```
|
188
197
|
|
189
198
|
If, on the other hand, no users on the free plan should have the
|
190
199
|
`:awesome` feature, place the following in
|
191
200
|
`config/initializers/arturo_initializer.rb`:
|
192
201
|
|
193
|
-
|
194
|
-
|
195
|
-
|
202
|
+
```Ruby
|
203
|
+
Arturo::Feature.blacklist(:awesome) do |user|
|
204
|
+
user.account.free?
|
205
|
+
end
|
206
|
+
```
|
196
207
|
|
197
208
|
If you want to whitelist or blacklist large groups of features at once, you
|
198
209
|
can move the feature argument into the block:
|
199
210
|
|
200
|
-
|
201
|
-
|
202
|
-
|
211
|
+
```Ruby
|
212
|
+
Arturo::Feature.whitelist do |feature, user|
|
213
|
+
user.account.has?(feature.to_sym)
|
214
|
+
end
|
215
|
+
```
|
203
216
|
|
204
217
|
### Feature Conditionals
|
205
218
|
|
@@ -214,9 +227,11 @@ use a before filter. The following will raise a 403 Forbidden error for
|
|
214
227
|
every action within `BookHoldsController` that is invoked by a user who
|
215
228
|
does not have the `:hold_book` feature.
|
216
229
|
|
217
|
-
|
218
|
-
|
219
|
-
|
230
|
+
```Ruby
|
231
|
+
class BookHoldsController < ApplicationController
|
232
|
+
require_feature :hold_book
|
233
|
+
end
|
234
|
+
```
|
220
235
|
|
221
236
|
`require_feature` accepts as a second argument a `Hash` that it passes on
|
222
237
|
to `before_action`, so you can use `:only` and `:except` to specify exactly
|
@@ -229,26 +244,32 @@ check there before falling back on Arturo's forbidden page.
|
|
229
244
|
|
230
245
|
#### Conditional Evaluation
|
231
246
|
|
232
|
-
Both controllers and views have access to the `if_feature_enabled
|
247
|
+
Both controllers and views have access to the `if_feature_enabled?` and
|
233
248
|
`feature_enabled?` methods. The former is used like so:
|
234
249
|
|
235
|
-
|
236
|
-
|
237
|
-
|
250
|
+
```ERB
|
251
|
+
<% if_feature_enabled?(:reserve_table) %>
|
252
|
+
<%= link_to 'Reserve a table', new_restaurant_reservation_path(:restaurant_id => @restaurant) %>
|
253
|
+
<% end %>
|
254
|
+
```
|
238
255
|
|
239
256
|
The latter can be used like so:
|
240
257
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
258
|
+
```Ruby
|
259
|
+
def widgets_for_sidebar
|
260
|
+
widgets = []
|
261
|
+
widgets << twitter_widget if feature_enabled?(:twitter_integration)
|
262
|
+
...
|
263
|
+
widgets
|
264
|
+
end
|
265
|
+
```
|
247
266
|
|
248
267
|
#### Rack Middleware
|
249
268
|
|
250
|
-
|
251
|
-
|
269
|
+
```Ruby
|
270
|
+
require 'arturo'
|
271
|
+
use Arturo::Middleware, feature: :my_feature
|
272
|
+
```
|
252
273
|
|
253
274
|
#### Outside a Controller
|
254
275
|
|
@@ -256,11 +277,15 @@ If you want to check availability outside of a controller or view (really
|
|
256
277
|
outside of something that has `Arturo::FeatureAvailability` mixed in), you
|
257
278
|
can ask either
|
258
279
|
|
259
|
-
|
280
|
+
```Ruby
|
281
|
+
Arturo.feature_enabled_for?(:foo, recipient)
|
282
|
+
```
|
260
283
|
|
261
284
|
or the slightly fancier
|
262
285
|
|
263
|
-
|
286
|
+
```Ruby
|
287
|
+
Arturo.foo_enabled_for?(recipient)
|
288
|
+
```
|
264
289
|
|
265
290
|
Both check whether the `foo` feature exists and is enabled for `recipient`.
|
266
291
|
|
@@ -276,12 +301,16 @@ To enable caching `Feature` lookups, mix `Arturo::FeatureCaching` into
|
|
276
301
|
`Arturo::Feature` and set the `cache_ttl`. This is best done in an
|
277
302
|
initializer:
|
278
303
|
|
279
|
-
|
280
|
-
|
304
|
+
```Ruby
|
305
|
+
Arturo::Feature.extend(Arturo::FeatureCaching)
|
306
|
+
Arturo::Feature.cache_ttl = 10.minutes
|
307
|
+
````
|
281
308
|
|
282
309
|
You can also warm the cache on startup:
|
283
310
|
|
284
|
-
|
311
|
+
```Ruby
|
312
|
+
Arturo::Feature.warm_cache!
|
313
|
+
```
|
285
314
|
|
286
315
|
This will pre-fetch all `Feature`s and put them in the cache.
|
287
316
|
|
data/lib/arturo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arturo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James A. Rosen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '3.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '3.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rails
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '3.2'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '5.
|
42
|
+
version: '5.2'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: '3.2'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '5.
|
52
|
+
version: '5.2'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: sqlite3
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
198
|
version: '0'
|
199
199
|
requirements: []
|
200
200
|
rubyforge_project:
|
201
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.5.2
|
202
202
|
signing_key:
|
203
203
|
specification_version: 4
|
204
204
|
summary: Feature sliders, wrapped up in an engine
|