arturo 0.2.3.6 → 0.2.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -0
- data/lib/arturo.rb +1 -0
- data/lib/arturo/middleware.rb +60 -0
- data/lib/arturo/test_support.rb +4 -4
- metadata +71 -119
data/README.md
CHANGED
@@ -256,6 +256,11 @@ The latter can be used like so:
|
|
256
256
|
widgets
|
257
257
|
end
|
258
258
|
|
259
|
+
#### Rack Middleware
|
260
|
+
|
261
|
+
require 'arturo'
|
262
|
+
use Arturo::Middleware, :feature => :my_feature
|
263
|
+
|
259
264
|
#### Outside a Controller
|
260
265
|
|
261
266
|
If you want to check availability outside of a controller or view (really
|
data/lib/arturo.rb
CHANGED
@@ -6,6 +6,7 @@ module Arturo
|
|
6
6
|
require 'arturo/feature_caching'
|
7
7
|
require 'arturo/controller_filters'
|
8
8
|
require 'arturo/range_form_support'
|
9
|
+
require 'arturo/middleware'
|
9
10
|
require 'arturo/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR == 3
|
10
11
|
|
11
12
|
class <<self
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Arturo
|
2
|
+
# A Rack middleware that requires a feature to be present. By default,
|
3
|
+
# checks feature availability against an `arturo.recipient` object
|
4
|
+
# in the `env`. If that object is missing, this middleware always fails,
|
5
|
+
# even if the feature is available for everyone.
|
6
|
+
#
|
7
|
+
# ## Usage
|
8
|
+
#
|
9
|
+
# use Arturo::Middleware, :feature => :foo
|
10
|
+
#
|
11
|
+
# ## Options
|
12
|
+
#
|
13
|
+
# * feature -- the name of the feature to require, as a Symbol; required
|
14
|
+
#
|
15
|
+
# * recipient -- the key in the `env` hash under which the feature
|
16
|
+
# recipient can be found; defaults to "arturo.recipient".
|
17
|
+
# * on_unavailable -- a Rack-like object
|
18
|
+
# (has `#call(Hash) -> [status, headers, body]`) that
|
19
|
+
# is called when the feature is unavailable; defaults
|
20
|
+
# to returning `[ 404, {}, ['Not Found'] ]`.
|
21
|
+
class Middleware
|
22
|
+
|
23
|
+
MISSING_FEATURE_ERROR = "Cannot create an Arturo::Middleware without a :feature"
|
24
|
+
|
25
|
+
DEFAULT_RECIPIENT_KEY = 'arturo.recipient'
|
26
|
+
|
27
|
+
DEFAULT_ON_UNAVAILABLE = lambda { |env| [ 404, {}, ['Not Found'] ] }
|
28
|
+
|
29
|
+
def initialize(app, options = {})
|
30
|
+
@app = app
|
31
|
+
@feature = options[:feature]
|
32
|
+
raise ArgumentError.new(MISSING_FEATURE_ERROR) unless @feature
|
33
|
+
@recipient_key = options[:recipient] || DEFAULT_RECIPIENT_KEY
|
34
|
+
@on_unavailable = options[:on_unavailable] || DEFAULT_ON_UNAVAILABLE
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(env)
|
38
|
+
if enabled_for_recipient?(env)
|
39
|
+
@app.call(env)
|
40
|
+
else
|
41
|
+
fail(env)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def enabled_for_recipient?(env)
|
48
|
+
::Arturo.feature_enabled_for?(@feature, recipient(env))
|
49
|
+
end
|
50
|
+
|
51
|
+
def recipient(env)
|
52
|
+
env[@recipient_key]
|
53
|
+
end
|
54
|
+
|
55
|
+
def fail(env)
|
56
|
+
@on_unavailable.call(env)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/arturo/test_support.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Arturo.
|
1
|
+
Arturo.instance_eval do
|
2
2
|
|
3
3
|
# Enable a feature; create it if necessary.
|
4
4
|
# For use in testing. Not auto-required on load. To load,
|
@@ -7,11 +7,11 @@ Arturo.class_eval do
|
|
7
7
|
#
|
8
8
|
# @param [Symbol, String] name the feature name
|
9
9
|
def enable_feature!(name)
|
10
|
-
feature = Arturo::Feature.
|
10
|
+
feature = Arturo::Feature.to_feature(name)
|
11
11
|
if feature
|
12
12
|
feature.update_attributes(:deployment_percentage => 100)
|
13
13
|
else
|
14
|
-
Arturo::Feature.create(:symbol => name, :deployment_percentage => 100)
|
14
|
+
Arturo::Feature.create!(:symbol => name, :deployment_percentage => 100)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -22,7 +22,7 @@ Arturo.class_eval do
|
|
22
22
|
#
|
23
23
|
# @param [Symbol, String] name the feature name
|
24
24
|
def disable_feature!(name)
|
25
|
-
if (feature = Arturo::Feature.
|
25
|
+
if (feature = Arturo::Feature.to_feature(name))
|
26
26
|
feature.update_attributes(:deployment_percentage => 0)
|
27
27
|
end
|
28
28
|
end
|
metadata
CHANGED
@@ -1,143 +1,106 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: arturo
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
- 6
|
11
|
-
version: 0.2.3.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3.7
|
5
|
+
prerelease:
|
12
6
|
platform: ruby
|
13
|
-
authors:
|
7
|
+
authors:
|
14
8
|
- James A. Rosen
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
23
15
|
name: rails
|
24
|
-
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2160470160 !ruby/object:Gem::Requirement
|
26
17
|
none: false
|
27
|
-
requirements:
|
18
|
+
requirements:
|
28
19
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 19
|
31
|
-
segments:
|
32
|
-
- 2
|
33
|
-
- 3
|
34
|
-
- 8
|
20
|
+
- !ruby/object:Gem::Version
|
35
21
|
version: 2.3.8
|
36
22
|
type: :runtime
|
37
|
-
version_requirements: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: mocha
|
40
23
|
prerelease: false
|
41
|
-
|
24
|
+
version_requirements: *2160470160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &2160469760 !ruby/object:Gem::Requirement
|
42
28
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
50
33
|
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: rake
|
54
34
|
prerelease: false
|
55
|
-
|
35
|
+
version_requirements: *2160469760
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2160469300 !ruby/object:Gem::Requirement
|
56
39
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
64
44
|
type: :development
|
65
|
-
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: redgreen
|
68
45
|
prerelease: false
|
69
|
-
|
46
|
+
version_requirements: *2160469300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: redgreen
|
49
|
+
requirement: &2160468800 !ruby/object:Gem::Requirement
|
70
50
|
none: false
|
71
|
-
requirements:
|
51
|
+
requirements:
|
72
52
|
- - ~>
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
76
|
-
- 1
|
77
|
-
- 2
|
78
|
-
version: "1.2"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
79
55
|
type: :development
|
80
|
-
version_requirements: *id004
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: sqlite3-ruby
|
83
56
|
prerelease: false
|
84
|
-
|
57
|
+
version_requirements: *2160468800
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sqlite3-ruby
|
60
|
+
requirement: &2160468300 !ruby/object:Gem::Requirement
|
85
61
|
none: false
|
86
|
-
requirements:
|
62
|
+
requirements:
|
87
63
|
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
segments:
|
91
|
-
- 1
|
92
|
-
- 3
|
93
|
-
version: "1.3"
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '1.3'
|
94
66
|
type: :development
|
95
|
-
version_requirements: *id005
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: factory_girl
|
98
67
|
prerelease: false
|
99
|
-
|
68
|
+
version_requirements: *2160468300
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl
|
71
|
+
requirement: &2160467840 !ruby/object:Gem::Requirement
|
100
72
|
none: false
|
101
|
-
requirements:
|
73
|
+
requirements:
|
102
74
|
- - ~>
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
|
105
|
-
segments:
|
106
|
-
- 1
|
107
|
-
- 3
|
108
|
-
version: "1.3"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
109
77
|
type: :development
|
110
|
-
version_requirements: *id006
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: timecop
|
113
78
|
prerelease: false
|
114
|
-
|
79
|
+
version_requirements: *2160467840
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: timecop
|
82
|
+
requirement: &2160467380 !ruby/object:Gem::Requirement
|
115
83
|
none: false
|
116
|
-
requirements:
|
84
|
+
requirements:
|
117
85
|
- - ~>
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
segments:
|
121
|
-
- 0
|
122
|
-
- 3
|
123
|
-
version: "0.3"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.3'
|
124
88
|
type: :development
|
125
|
-
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2160467380
|
126
91
|
description: Deploy features incrementally to your users
|
127
92
|
email: james.a.rosen@gmail.com
|
128
93
|
executables: []
|
129
|
-
|
130
94
|
extensions: []
|
131
|
-
|
132
95
|
extra_rdoc_files: []
|
133
|
-
|
134
|
-
files:
|
96
|
+
files:
|
135
97
|
- lib/arturo/controller_filters.rb
|
136
98
|
- lib/arturo/engine.rb
|
137
99
|
- lib/arturo/feature_availability.rb
|
138
100
|
- lib/arturo/feature_caching.rb
|
139
101
|
- lib/arturo/feature_factories.rb
|
140
102
|
- lib/arturo/feature_management.rb
|
103
|
+
- lib/arturo/middleware.rb
|
141
104
|
- lib/arturo/range_form_support.rb
|
142
105
|
- lib/arturo/special_handling.rb
|
143
106
|
- lib/arturo/test_support.rb
|
@@ -163,40 +126,29 @@ files:
|
|
163
126
|
- rails/init.rb
|
164
127
|
- README.md
|
165
128
|
- HISTORY.md
|
166
|
-
has_rdoc: true
|
167
129
|
homepage: http://github.com/jamesarosen/arturo
|
168
130
|
licenses: []
|
169
|
-
|
170
131
|
post_install_message:
|
171
132
|
rdoc_options: []
|
172
|
-
|
173
|
-
require_paths:
|
133
|
+
require_paths:
|
174
134
|
- .
|
175
135
|
- lib
|
176
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
137
|
none: false
|
178
|
-
requirements:
|
179
|
-
- -
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
|
182
|
-
|
183
|
-
- 0
|
184
|
-
version: "0"
|
185
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
143
|
none: false
|
187
|
-
requirements:
|
188
|
-
- -
|
189
|
-
- !ruby/object:Gem::Version
|
190
|
-
|
191
|
-
segments:
|
192
|
-
- 0
|
193
|
-
version: "0"
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
194
148
|
requirements: []
|
195
|
-
|
196
149
|
rubyforge_project:
|
197
|
-
rubygems_version: 1.
|
150
|
+
rubygems_version: 1.8.6
|
198
151
|
signing_key:
|
199
152
|
specification_version: 2
|
200
153
|
summary: Feature sliders, wrapped up in an engine
|
201
154
|
test_files: []
|
202
|
-
|