feature_creep 0.0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/feature_creep.rb +18 -7
- data/lib/feature_creep/redis_datastore.rb +8 -20
- data/lib/feature_creep/version.rb +1 -1
- data/spec/feature_creep_spec.rb +26 -5
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
data/lib/feature_creep.rb
CHANGED
@@ -5,11 +5,19 @@ class FeatureCreep
|
|
5
5
|
def initialize(datastore, options = {})
|
6
6
|
@datastore = datastore
|
7
7
|
@scopes = {"all" => lambda { |agent_id| true }}
|
8
|
+
|
8
9
|
if options.has_key?(:scopes)
|
9
10
|
options[:scopes].each do |name,membership_block|
|
10
11
|
@scopes[name.to_s] = membership_block
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
15
|
+
if options.has_key?(:features)
|
16
|
+
options[:features].each do |feature|
|
17
|
+
add_feature(feature)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
@warden = if options.has_key?(:warden)
|
14
22
|
options[:warden]
|
15
23
|
else
|
@@ -24,6 +32,7 @@ class FeatureCreep
|
|
24
32
|
end
|
25
33
|
}
|
26
34
|
end
|
35
|
+
|
27
36
|
@info = if options.has_key?(:info)
|
28
37
|
options[:info]
|
29
38
|
else lambda { |feature|
|
@@ -31,12 +40,14 @@ class FeatureCreep
|
|
31
40
|
{
|
32
41
|
:percentage => (active_percentage(feature) || 0).to_i,
|
33
42
|
:scopes => active_scopes(feature).map { |g| g.to_sym },
|
34
|
-
:agent_ids =>
|
35
|
-
:global => active_global_features
|
43
|
+
:agent_ids => active_agent_ids(feature),
|
44
|
+
:global => active_global_features,
|
45
|
+
:available_features => features
|
36
46
|
}
|
37
47
|
else
|
38
48
|
{
|
39
|
-
:global => active_global_features
|
49
|
+
:global => active_global_features,
|
50
|
+
:available_features => features
|
40
51
|
}
|
41
52
|
end
|
42
53
|
}
|
@@ -83,8 +94,8 @@ class FeatureCreep
|
|
83
94
|
@datastore.deactivate_percentage(feature)
|
84
95
|
end
|
85
96
|
|
86
|
-
def
|
87
|
-
@datastore.
|
97
|
+
def features
|
98
|
+
@datastore.features
|
88
99
|
end
|
89
100
|
|
90
101
|
def add_feature(feature)
|
@@ -99,8 +110,8 @@ class FeatureCreep
|
|
99
110
|
@datastore.active_scopes(feature)
|
100
111
|
end
|
101
112
|
|
102
|
-
def
|
103
|
-
@datastore.
|
113
|
+
def active_agent_ids(feature)
|
114
|
+
@datastore.active_agent_ids(feature)
|
104
115
|
end
|
105
116
|
|
106
117
|
def active_global_features
|
@@ -7,6 +7,7 @@ class FeatureCreep
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def activate_globally(feature)
|
10
|
+
add_feature(feature)
|
10
11
|
@redis.sadd(global_key, feature)
|
11
12
|
end
|
12
13
|
|
@@ -15,6 +16,7 @@ class FeatureCreep
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def activate_scope(feature, scope)
|
19
|
+
add_feature(feature)
|
18
20
|
@redis.sadd(scope_key(feature), scope)
|
19
21
|
end
|
20
22
|
|
@@ -30,6 +32,7 @@ class FeatureCreep
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def activate_agent_id(feature, agent_id)
|
35
|
+
add_feature(feature)
|
33
36
|
@redis.sadd(agent_id_key(feature), agent_id)
|
34
37
|
end
|
35
38
|
|
@@ -56,27 +59,12 @@ class FeatureCreep
|
|
56
59
|
@redis.del(percentage_key(feature))
|
57
60
|
end
|
58
61
|
|
59
|
-
def info(feature = nil)
|
60
|
-
if feature
|
61
|
-
{
|
62
|
-
:percentage => (active_percentage(feature) || 0).to_i,
|
63
|
-
:scopes => active_scopes(feature).map { |g| g.to_sym },
|
64
|
-
:agent_ids => active_agent_id_ids(feature),
|
65
|
-
:global => active_global_features
|
66
|
-
}
|
67
|
-
else
|
68
|
-
{
|
69
|
-
:features => current_features
|
70
|
-
}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
62
|
def active_scopes(feature)
|
75
63
|
@redis.smembers(scope_key(feature)) || []
|
76
64
|
end
|
77
65
|
|
78
|
-
def
|
79
|
-
@redis.smembers(agent_id_key(feature))
|
66
|
+
def active_agent_ids(feature)
|
67
|
+
@redis.smembers(agent_id_key(feature))
|
80
68
|
end
|
81
69
|
|
82
70
|
def active_global_features
|
@@ -101,12 +89,12 @@ class FeatureCreep
|
|
101
89
|
agent_id % 100 < percentage.to_i
|
102
90
|
end
|
103
91
|
|
104
|
-
def
|
105
|
-
@redis.smembers(@key_prefix)
|
92
|
+
def features
|
93
|
+
@redis.smembers(@key_prefix).map(&:to_sym)
|
106
94
|
end
|
107
95
|
|
108
96
|
def add_feature(feature)
|
109
|
-
redis.sadd(@key_prefix, feature)
|
97
|
+
@redis.sadd(@key_prefix, feature)
|
110
98
|
end
|
111
99
|
|
112
100
|
private
|
data/spec/feature_creep_spec.rb
CHANGED
@@ -6,7 +6,25 @@ describe "FeatureCreep" do
|
|
6
6
|
scopes = {
|
7
7
|
:fivesonly => lambda { |agent_id| agent_id == 5 }
|
8
8
|
}
|
9
|
-
@feature_creep = FeatureCreep.new(@datastore, {:scopes => scopes})
|
9
|
+
@feature_creep = FeatureCreep.new(@datastore, {:scopes => scopes, :features => [:test1, :test2]})
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".new" do
|
13
|
+
it "sets features" do
|
14
|
+
@feature_creep.features.should == [:test1, :test2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets @scopes" do
|
18
|
+
@feature_creep.scopes['fivesonly'].should be_a Proc
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets @info" do
|
22
|
+
@feature_creep.info.should be_a Hash
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets @warden" do
|
26
|
+
@feature_creep.warden.should be_a Proc
|
27
|
+
end
|
10
28
|
end
|
11
29
|
|
12
30
|
describe "when a scope is activated" do
|
@@ -177,6 +195,7 @@ describe "FeatureCreep" do
|
|
177
195
|
describe "#info" do
|
178
196
|
context "global features" do
|
179
197
|
let(:features) { [:signup, :chat, :table] }
|
198
|
+
let(:available_features) { [:chat, :test1, :signup, :test2, :table] }
|
180
199
|
|
181
200
|
before do
|
182
201
|
features.each do |f|
|
@@ -185,7 +204,7 @@ describe "FeatureCreep" do
|
|
185
204
|
end
|
186
205
|
|
187
206
|
it "returns all global features" do
|
188
|
-
@feature_creep.info.should eq({ :global => features.reverse })
|
207
|
+
@feature_creep.info.should eq({ :global => features.reverse, :available_features => available_features })
|
189
208
|
end
|
190
209
|
end
|
191
210
|
|
@@ -202,8 +221,9 @@ describe "FeatureCreep" do
|
|
202
221
|
@feature_creep.info(:chat).should == {
|
203
222
|
:percentage => 10,
|
204
223
|
:scopes => [:greeters, :caretakers],
|
205
|
-
:agent_ids => [42],
|
206
|
-
:global => [:signup]
|
224
|
+
:agent_ids => ["42"],
|
225
|
+
:global => [:signup],
|
226
|
+
:available_features => [:chat, :test1, :signup, :test2]
|
207
227
|
}
|
208
228
|
end
|
209
229
|
end
|
@@ -214,7 +234,8 @@ describe "FeatureCreep" do
|
|
214
234
|
:percentage => 0,
|
215
235
|
:scopes => [],
|
216
236
|
:agent_ids => [],
|
217
|
-
:global => []
|
237
|
+
:global => [],
|
238
|
+
:available_features=>[:test1, :test2]
|
218
239
|
}
|
219
240
|
end
|
220
241
|
end
|
data/spec/spec_helper.rb
CHANGED