arturo 2.3.0 → 2.4.0

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: 4624ac43327363d7ca57fe40f5af1bdc987db5cd
4
- data.tar.gz: 540a689b5338d59e1635042c111c133f3fbab00e
3
+ metadata.gz: a02a4e7e0db51f26446e2c7b0c1cf52074b7e248
4
+ data.tar.gz: ec2c34461ec09ff68eade07571b9f9e556236b87
5
5
  SHA512:
6
- metadata.gz: 61c88a69a0ede466a7b1d1fbe3448ac34c1576ba56f6080da83039e2564dfd61fccb52909ee80a1e5d56cfd90a3d255ea950075a4efda4fd7bc117a3a30e20ac
7
- data.tar.gz: 13c037207a89491d695bc549963c8cb18f39b34602edeca9d980c58f3b275d075eb7ba9e022ca0a8d2cb82d16bbbb6247802b21be0fc5460f9ac06c451e5e3cd
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
- * The selection isn't random. It's not even pseudo-random. It's completely
11
- deterministic. This assures that if a user has a feature on Monday, the
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
- <%# in app/views/layout/_sidebar.html.erb: %>
23
- <% if_feature_enabled(:live_postings) do %>
24
- <div class='widget'>
25
- <h3>Recent Postings</h3>
26
- <ol id='live_postings'>
27
- </ol>
28
- </div>
29
- <% end %>
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
- // 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
- });
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
- # in app/controllers/postings_controller:
50
- class PostingsController < ApplicationController
51
- require_feature :live_postings, :only => :recent
52
- # ...
53
- end
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
- gem 'arturo', '~> 1.0'
72
-
73
- ### In Rails 3 or 4, without Bundler
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
- $ rails g arturo:migration
89
- $ rails g arturo:initializer
90
- $ rails g arturo:routes
91
- $ rails g arturo:assets
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
- $ rake db:migrate
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
- current_user.present? && current_user.admin?
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
- Arturo.permit_management do
144
- signed_in? && current_user.can?(:manage_features)
145
- end
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
- Arturo.feature_recipient do
167
- current_account
168
- end
169
+ ```Ruby
170
+ Arturo.feature_recipient do
171
+ current_account
172
+ end
173
+ ```
169
174
 
170
175
  or
171
176
 
172
- Arturo.feature_recipient do
173
- current_user.account
174
- end
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
- Arturo::Feature.whitelist(:awesome) do |user|
186
- user.account.premium?
187
- end
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
- Arturo::Feature.blacklist(:awesome) do |user|
194
- user.account.free?
195
- end
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
- Arturo::Feature.whitelist do |feature, user|
201
- user.account.has?(feature.to_sym)
202
- end
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
- class BookHoldsController < ApplicationController
218
- require_feature :hold_book
219
- end
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` and
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
- <% if_feature_enabled?(:reserve_table) %>
236
- <%= link_to 'Reserve a table', new_restaurant_reservation_path(:restaurant_id => @restaurant) %>
237
- <% end %>
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
- def widgets_for_sidebar
242
- widgets = []
243
- widgets << twitter_widget if feature_enabled?(:twitter_integration)
244
- ...
245
- widgets
246
- end
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
- require 'arturo'
251
- use Arturo::Middleware, :feature => :my_feature
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
- Arturo.feature_enabled_for?(:foo, recipient)
280
+ ```Ruby
281
+ Arturo.feature_enabled_for?(:foo, recipient)
282
+ ```
260
283
 
261
284
  or the slightly fancier
262
285
 
263
- Arturo.foo_enabled_for?(recipient)
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
- Arturo::Feature.extend(Arturo::FeatureCaching)
280
- Arturo::Feature.cache_ttl = 10.minutes
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
- Arturo::Feature.warm_cache!
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
 
@@ -25,7 +25,7 @@ module Arturo
25
25
  end
26
26
 
27
27
  # By default, returns current_user.
28
- #
28
+ #
29
29
  # If you would like to change this implementation, it is recommended
30
30
  # you do so in config/initializers/arturo_initializer.rb
31
31
  # @return [Object] the recipient of features.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Arturo
3
- VERSION = '2.3.0'
3
+ VERSION = '2.4.0'
4
4
  end
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.3.0
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: 2016-12-06 00:00:00.000000000 Z
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.1'
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.1'
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.1'
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.1'
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.4.5.1
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