flipper 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -4
- data/lib/flipper/dsl.rb +2 -12
- data/lib/flipper/gates/actor.rb +4 -3
- data/lib/flipper/types/actor.rb +34 -2
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/feature_spec.rb +34 -2
- data/spec/flipper/types/actor_spec.rb +103 -5
- data/spec/helper.rb +0 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/lib/flipper/dsl.rb
CHANGED
@@ -34,18 +34,8 @@ module Flipper
|
|
34
34
|
Flipper.group(name)
|
35
35
|
end
|
36
36
|
|
37
|
-
def actor(
|
38
|
-
|
39
|
-
|
40
|
-
identifier = if actor_or_number.respond_to?(:identifier)
|
41
|
-
actor_or_number.identifier
|
42
|
-
elsif actor_or_number.respond_to?(:id)
|
43
|
-
actor_or_number.id
|
44
|
-
else
|
45
|
-
actor_or_number
|
46
|
-
end
|
47
|
-
|
48
|
-
Flipper::Types::Actor.new(identifier)
|
37
|
+
def actor(thing)
|
38
|
+
Flipper::Types::Actor.new(thing)
|
49
39
|
end
|
50
40
|
|
51
41
|
def random(number)
|
data/lib/flipper/gates/actor.rb
CHANGED
@@ -12,9 +12,10 @@ module Flipper
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def open?(actor)
|
15
|
-
if actor
|
16
|
-
|
17
|
-
|
15
|
+
return if actor.nil?
|
16
|
+
return unless Types::Actor.wrappable?(actor)
|
17
|
+
actor = Types::Actor.wrap(actor)
|
18
|
+
identifiers.include?(actor.identifier)
|
18
19
|
end
|
19
20
|
|
20
21
|
def identifiers
|
data/lib/flipper/types/actor.rb
CHANGED
@@ -1,10 +1,34 @@
|
|
1
1
|
module Flipper
|
2
2
|
module Types
|
3
3
|
class Actor < Type
|
4
|
+
def self.wrappable?(thing)
|
5
|
+
thing.is_a?(Flipper::Types::Actor) ||
|
6
|
+
thing.respond_to?(:identifier) ||
|
7
|
+
thing.respond_to?(:id) ||
|
8
|
+
thing.respond_to?(:to_i)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.wrap(thing)
|
12
|
+
if thing.is_a?(Flipper::Types::Actor)
|
13
|
+
thing
|
14
|
+
else
|
15
|
+
new(thing)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
4
19
|
attr_reader :identifier
|
5
20
|
|
6
|
-
def initialize(
|
7
|
-
|
21
|
+
def initialize(thing)
|
22
|
+
raise ArgumentError, "thing cannot be nil" if thing.nil?
|
23
|
+
|
24
|
+
@thing = thing
|
25
|
+
@identifier = if thing.respond_to?(:identifier)
|
26
|
+
thing.identifier
|
27
|
+
elsif thing.respond_to?(:id)
|
28
|
+
thing.id
|
29
|
+
else
|
30
|
+
thing
|
31
|
+
end.to_i
|
8
32
|
end
|
9
33
|
|
10
34
|
def enabled_value
|
@@ -12,6 +36,14 @@ module Flipper
|
|
12
36
|
end
|
13
37
|
|
14
38
|
alias_method :disabled_value, :enabled_value
|
39
|
+
|
40
|
+
def respond_to?(*args)
|
41
|
+
super || @thing.respond_to?(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(name, *args, &block)
|
45
|
+
@thing.send name, *args, &block
|
46
|
+
end
|
15
47
|
end
|
16
48
|
end
|
17
49
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -15,8 +15,8 @@ describe Flipper::Feature do
|
|
15
15
|
let(:admin_group) { Flipper.group(:admins) }
|
16
16
|
let(:dev_group) { Flipper.group(:devs) }
|
17
17
|
|
18
|
-
let(:admin_thing) { double 'Non Flipper Thing', :admin? => true, :dev? => false }
|
19
|
-
let(:dev_thing) { double 'Non Flipper Thing', :admin? => false, :dev? => true }
|
18
|
+
let(:admin_thing) { double 'Non Flipper Thing', :identifier => 1, :admin? => true, :dev? => false }
|
19
|
+
let(:dev_thing) { double 'Non Flipper Thing', :identifier => 10, :admin? => false, :dev? => true }
|
20
20
|
|
21
21
|
let(:pitt) { Flipper::Types::Actor.new(1) }
|
22
22
|
let(:clooney) { Flipper::Types::Actor.new(10) }
|
@@ -62,6 +62,14 @@ describe Flipper::Feature do
|
|
62
62
|
subject.enabled?(dev_thing).should be_false
|
63
63
|
end
|
64
64
|
|
65
|
+
it "enables feature for flipper actor in group" do
|
66
|
+
subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does not enable for flipper actor not in group" do
|
70
|
+
subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_false
|
71
|
+
end
|
72
|
+
|
65
73
|
it "does not enable feature for all" do
|
66
74
|
subject.enabled?.should be_false
|
67
75
|
end
|
@@ -153,6 +161,14 @@ describe Flipper::Feature do
|
|
153
161
|
it "does not disable feature for non flipper thing in other groups" do
|
154
162
|
subject.enabled?(dev_thing).should be_true
|
155
163
|
end
|
164
|
+
|
165
|
+
it "disables feature for flipper actor in group" do
|
166
|
+
subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_false
|
167
|
+
end
|
168
|
+
|
169
|
+
it "does not disable feature for flipper actor in other groups" do
|
170
|
+
subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_true
|
171
|
+
end
|
156
172
|
end
|
157
173
|
|
158
174
|
context "with an actor" do
|
@@ -230,6 +246,22 @@ describe Flipper::Feature do
|
|
230
246
|
end
|
231
247
|
end
|
232
248
|
|
249
|
+
context "for actor in enabled group" do
|
250
|
+
before do
|
251
|
+
adapter.set_add("#{subject.name}#{Flipper::Gate::Separator}#{group_key}", admin_group.name)
|
252
|
+
end
|
253
|
+
|
254
|
+
it "returns true" do
|
255
|
+
subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_true
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "for actor in disbled group" do
|
260
|
+
it "returns false" do
|
261
|
+
subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_false
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
233
265
|
context "for enabled actor" do
|
234
266
|
before do
|
235
267
|
adapter.set_add("#{subject.name}#{Flipper::Gate::Separator}#{actor_key}", pitt.identifier)
|
@@ -3,21 +3,119 @@ require 'flipper/types/actor'
|
|
3
3
|
|
4
4
|
describe Flipper::Types::Actor do
|
5
5
|
subject {
|
6
|
-
|
6
|
+
described_class.new(2)
|
7
7
|
}
|
8
8
|
|
9
|
+
let(:thing_class) {
|
10
|
+
Class.new {
|
11
|
+
attr_reader :identifier
|
12
|
+
|
13
|
+
def initialize(identifier)
|
14
|
+
@identifier = identifier
|
15
|
+
end
|
16
|
+
|
17
|
+
def admin?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
describe ".wrappable?" do
|
24
|
+
it "returns true if actor" do
|
25
|
+
thing = described_class.new(1)
|
26
|
+
described_class.wrappable?(thing).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns true if responds to identifier" do
|
30
|
+
thing = Struct.new(:identifier).new(10)
|
31
|
+
described_class.wrappable?(thing).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns true if responds to id" do
|
35
|
+
thing = Struct.new(:id).new(10)
|
36
|
+
described_class.wrappable?(thing).should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns true if responds to to_i" do
|
40
|
+
described_class.wrappable?(1).should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false if not actor and does not respond to identifier, id, nor to_i" do
|
44
|
+
described_class.wrappable?(:nope).should be_false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".wrap" do
|
49
|
+
context "for actor" do
|
50
|
+
it "returns actor" do
|
51
|
+
actor = described_class.wrap(subject)
|
52
|
+
actor.should be_instance_of(described_class)
|
53
|
+
actor.should be(subject)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "for other thing" do
|
58
|
+
it "returns actor" do
|
59
|
+
actor = described_class.wrap(1)
|
60
|
+
actor.should be_instance_of(described_class)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
9
65
|
it "initializes with identifier" do
|
10
|
-
actor =
|
11
|
-
actor.should be_instance_of(
|
66
|
+
actor = described_class.new(2)
|
67
|
+
actor.should be_instance_of(described_class)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "initializes with object that responds to identifier" do
|
71
|
+
thing = Struct.new(:identifier).new(1)
|
72
|
+
actor = described_class.new(thing)
|
73
|
+
actor.identifier.should be(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "initializes with object that responds to id" do
|
77
|
+
thing = Struct.new(:id).new(13)
|
78
|
+
actor = described_class.new(thing)
|
79
|
+
actor.identifier.should be(13)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises error when initialized with nil" do
|
83
|
+
expect {
|
84
|
+
described_class.new(nil)
|
85
|
+
}.to raise_error(ArgumentError)
|
12
86
|
end
|
13
87
|
|
14
88
|
it "converts identifier to integer" do
|
15
|
-
actor =
|
89
|
+
actor = described_class.new('2')
|
16
90
|
actor.identifier.should eq(2)
|
17
91
|
end
|
18
92
|
|
19
93
|
it "has identifier" do
|
20
|
-
actor =
|
94
|
+
actor = described_class.new(2)
|
21
95
|
actor.identifier.should eq(2)
|
22
96
|
end
|
97
|
+
|
98
|
+
it "proxies everything to thing" do
|
99
|
+
thing = thing_class.new(10)
|
100
|
+
actor = described_class.new(thing)
|
101
|
+
actor.admin?.should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#respond_to?" do
|
105
|
+
it "returns true if responds to method" do
|
106
|
+
actor = described_class.new(10)
|
107
|
+
actor.respond_to?(:enabled_value).should be_true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "returns true if thing responds to method" do
|
111
|
+
thing = thing_class.new(10)
|
112
|
+
actor = described_class.new(thing)
|
113
|
+
actor.respond_to?(:admin?).should be_true
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns false if does not respond to method and thing does not respond to method" do
|
117
|
+
actor = described_class.new(10)
|
118
|
+
actor.respond_to?(:frankenstein).should be_false
|
119
|
+
end
|
120
|
+
end
|
23
121
|
end
|
data/spec/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Feature flipper for any adapter
|
15
15
|
email:
|
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
segments:
|
91
91
|
- 0
|
92
|
-
hash:
|
92
|
+
hash: 1261844147465808882
|
93
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
segments:
|
100
100
|
- 0
|
101
|
-
hash:
|
101
|
+
hash: 1261844147465808882
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
104
|
rubygems_version: 1.8.10
|