feature_creep 0.0.1 → 0.1.2

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.
@@ -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 => active_agent_id_ids(feature),
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 current_features
87
- @datastore.current_features
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 active_agent_id_ids(feature)
103
- @datastore.active_agent_id_ids(feature)
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 active_agent_id_ids(feature)
79
- @redis.smembers(agent_id_key(feature)).map { |id| id.to_i }
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 current_features
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
@@ -1,3 +1,3 @@
1
1
  class FeatureCreep
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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
@@ -5,6 +5,7 @@ require 'feature_creep/redis_datastore'
5
5
  require 'rspec'
6
6
  require 'bourne'
7
7
  require 'redis'
8
+ require 'pry'
8
9
 
9
10
  RSpec.configure do |config|
10
11
  config.mock_with :mocha
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_creep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: