rollout 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -44,6 +44,14 @@ class Rollout
44
44
  @redis.del(percentage_key(feature))
45
45
  end
46
46
 
47
+ def info(feature)
48
+ {
49
+ :percentage => (active_percentage(feature) || 0).to_i,
50
+ :groups => active_groups(feature).map { |g| g.to_sym },
51
+ :users => active_user_ids(feature)
52
+ }
53
+ end
54
+
47
55
  private
48
56
  def key(name)
49
57
  "feature:#{name}"
@@ -61,8 +69,22 @@ class Rollout
61
69
  "#{key(name)}:percentage"
62
70
  end
63
71
 
72
+ def active_groups(feature)
73
+ @redis.smembers(group_key(feature)) || []
74
+ end
75
+
76
+ def active_user_ids(feature)
77
+ @redis.smembers(user_key(feature)).map { |id| id.to_i }
78
+ end
79
+
80
+ def active_percentage(feature)
81
+ @redis.get(percentage_key(feature))
82
+ end
83
+
64
84
  def user_in_active_group?(feature, user)
65
- (@redis.smembers(group_key(feature)) || []).any? { |group| @groups.key?(group) && @groups[group].call(user) }
85
+ active_groups(feature).any? do |group|
86
+ @groups.key?(group) && @groups[group].call(user)
87
+ end
66
88
  end
67
89
 
68
90
  def user_active?(feature, user)
@@ -70,7 +92,7 @@ class Rollout
70
92
  end
71
93
 
72
94
  def user_within_active_percentage?(feature, user)
73
- percentage = @redis.get(percentage_key(feature))
95
+ percentage = active_percentage(feature)
74
96
  return false if percentage.nil?
75
97
  user.id % 100 < percentage.to_i
76
98
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rollout"
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Golick"]
12
- s.date = "2011-10-06"
12
+ s.date = "2012-02-20"
13
13
  s.description = "Conditionally roll out features with redis."
14
14
  s.email = "jamesgoick@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  ]
31
31
  s.homepage = "http://github.com/jamesgolick/rollout"
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = "1.3.9.3"
33
+ s.rubygems_version = "1.8.10"
34
34
  s.summary = "Conditionally roll out features with redis."
35
35
 
36
36
  if s.respond_to? :specification_version then
@@ -147,4 +147,36 @@ describe "Rollout" do
147
147
  @rollout.should_not be_active(:chat, stub(:id => 24))
148
148
  end
149
149
  end
150
+
151
+ describe "#info" do
152
+ describe "with a percentage set" do
153
+ before do
154
+ @rollout.activate_percentage(:chat, 10)
155
+ @rollout.activate_group(:chat, :caretakers)
156
+ @rollout.activate_group(:chat, :greeters)
157
+ @rollout.activate_user(:chat, stub(:id => 42))
158
+ end
159
+
160
+ it "returns info about all the activations" do
161
+ @rollout.info(:chat).should == {
162
+ :percentage => 10,
163
+ :groups => [:greeters, :caretakers],
164
+ :users => [42]
165
+ }
166
+ end
167
+ end
168
+
169
+ describe "without a percentage set" do
170
+ before do
171
+ end
172
+
173
+ it "the percentage defaults to 0" do
174
+ @rollout.info(:chat).should == {
175
+ :percentage => 0,
176
+ :groups => [],
177
+ :users => []
178
+ }
179
+ end
180
+ end
181
+ end
150
182
  end
metadata CHANGED
@@ -1,80 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rollout
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - James Golick
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-06 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70160153622800 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - "="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.2.9
35
22
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: bourne
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70160153622800
25
+ - !ruby/object:Gem::Dependency
26
+ name: bourne
27
+ requirement: &70160153621860 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
45
- hash: 23
46
- segments:
47
- - 1
48
- - 0
49
- - 0
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
50
32
  version: 1.0.0
51
33
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: redis
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70160153621860
36
+ - !ruby/object:Gem::Dependency
37
+ name: redis
38
+ requirement: &70160153619840 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
59
- - - "="
60
- - !ruby/object:Gem::Version
61
- hash: 9
62
- segments:
63
- - 0
64
- - 1
65
- version: "0.1"
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
43
+ version: '0.1'
66
44
  type: :development
67
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70160153619840
68
47
  description: Conditionally roll out features with redis.
69
48
  email: jamesgoick@gmail.com
70
49
  executables: []
71
-
72
50
  extensions: []
73
-
74
- extra_rdoc_files:
51
+ extra_rdoc_files:
75
52
  - LICENSE
76
53
  - README.rdoc
77
- files:
54
+ files:
78
55
  - .document
79
56
  - LICENSE
80
57
  - README.rdoc
@@ -85,39 +62,28 @@ files:
85
62
  - spec/rollout_spec.rb
86
63
  - spec/spec.opts
87
64
  - spec/spec_helper.rb
88
- has_rdoc: true
89
65
  homepage: http://github.com/jamesgolick/rollout
90
66
  licenses: []
91
-
92
67
  post_install_message:
93
68
  rdoc_options: []
94
-
95
- require_paths:
69
+ require_paths:
96
70
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ required_ruby_version: !ruby/object:Gem::Requirement
98
72
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
78
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
115
83
  requirements: []
116
-
117
84
  rubyforge_project:
118
- rubygems_version: 1.3.9.3
85
+ rubygems_version: 1.8.10
119
86
  signing_key:
120
87
  specification_version: 3
121
88
  summary: Conditionally roll out features with redis.
122
89
  test_files: []
123
-