flipper 0.7.0.beta5 → 0.7.0.beta6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21326996e956e478ea5268d560e374601bf14552
4
- data.tar.gz: a689bd8f70d6bb8f4dfd466b09c8140541f882d1
3
+ metadata.gz: fbc4122278d701b4a97828cb9fbfe1f66328ff48
4
+ data.tar.gz: 87a4ad6f4b5da8b4a3c9d61fae53231a156f10c3
5
5
  SHA512:
6
- metadata.gz: 8ebf9a133a5c1d940557f5bed521541ff7952d8ec8ce0d9277cbf3721595bf5ae2a03946f1d3e22850f29469ace8d1d08d72b940b8e48064c9157a48cfe581e2
7
- data.tar.gz: 0746cac8cd3ed19daf90cecdf105537fc1e9fc841a9f31411603c0f463cd30a5717d563a3f5b8cf18a7a847213245fcc3961f1248b06fc0aade0c23e507e0c74
6
+ metadata.gz: 0f870e8966135ca803eb0aabe97dce999cd710db15720d67374a8b81e1fc13f608e7ba0ec082b079075b6b8c2a6509bc37db5b8b5af1e27f758b5de4a31de7db
7
+ data.tar.gz: b5f89715dcb5e10989f1e2fd2f63cc19d62854011d1f08aee29f1d3e7cc17d7280638c12d98576dcf099f5960cbc0f6e25d7f3868fac0a942f6259d6a8eb92a3
@@ -43,13 +43,15 @@ module Flipper
43
43
  #
44
44
  # Returns the result of Adapter#enable.
45
45
  def enable(thing = true)
46
- instrument(:enable, thing) { |payload|
46
+ instrument(:enable) { |payload|
47
47
  adapter.add self
48
48
 
49
49
  gate = gate_for(thing)
50
+ wrapped_thing = gate.wrap(thing)
50
51
  payload[:gate_name] = gate.name
52
+ payload[:thing] = wrapped_thing
51
53
 
52
- adapter.enable self, gate, gate.wrap(thing)
54
+ adapter.enable self, gate, wrapped_thing
53
55
  }
54
56
  end
55
57
 
@@ -57,16 +59,18 @@ module Flipper
57
59
  #
58
60
  # Returns the result of Adapter#disable.
59
61
  def disable(thing = false)
60
- instrument(:disable, thing) { |payload|
62
+ instrument(:disable) { |payload|
61
63
  adapter.add self
62
64
 
63
65
  gate = gate_for(thing)
66
+ wrapped_thing = gate.wrap(thing)
64
67
  payload[:gate_name] = gate.name
68
+ payload[:thing] = wrapped_thing
65
69
 
66
70
  if gate.is_a?(Gates::Boolean)
67
71
  adapter.clear self
68
72
  else
69
- adapter.disable self, gate, gate.wrap(thing)
73
+ adapter.disable self, gate, wrapped_thing
70
74
  end
71
75
  }
72
76
  end
@@ -75,9 +79,11 @@ module Flipper
75
79
  #
76
80
  # Returns true if enabled, false if not.
77
81
  def enabled?(thing = nil)
78
- instrument(:enabled?, thing) { |payload|
82
+ instrument(:enabled?) { |payload|
79
83
  values = gate_values
80
84
 
85
+ payload[:thing] = gate(:actor).wrap(thing) unless thing.nil?
86
+
81
87
  open_gate = gates.detect { |gate|
82
88
  instrument_gate(gate, :open?, thing) { |gate_payload|
83
89
  gate.open?(thing, values[gate.key], feature_name: @name)
@@ -343,14 +349,10 @@ module Flipper
343
349
  private
344
350
 
345
351
  # Private: Instrument a feature operation.
346
- def instrument(operation, thing)
347
- payload = {
348
- :feature_name => name,
349
- :operation => operation,
350
- :thing => thing,
351
- }
352
-
353
- @instrumenter.instrument(InstrumentationName, payload) { |payload|
352
+ def instrument(operation)
353
+ @instrumenter.instrument(InstrumentationName) { |payload|
354
+ payload[:feature_name] = name
355
+ payload[:operation] = operation
354
356
  payload[:result] = yield(payload) if block_given?
355
357
  }
356
358
  end
@@ -37,8 +37,12 @@ module Flipper
37
37
  end
38
38
  end
39
39
 
40
+ def wrap(thing)
41
+ Types::Group.wrap(thing)
42
+ end
43
+
40
44
  def protects?(thing)
41
- thing.is_a?(Types::Group)
45
+ thing.is_a?(Types::Group) || thing.is_a?(Symbol)
42
46
  end
43
47
  end
44
48
  end
@@ -6,6 +6,8 @@ module Flipper
6
6
  thing.respond_to?(:flipper_id)
7
7
  end
8
8
 
9
+ attr_reader :thing
10
+
9
11
  def initialize(thing)
10
12
  if thing.nil?
11
13
  raise ArgumentError.new("thing cannot be nil")
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = "0.7.0.beta5"
2
+ VERSION = "0.7.0.beta6"
3
3
  end
@@ -115,7 +115,7 @@ describe Flipper::Feature do
115
115
  }
116
116
 
117
117
  it "is recorded for enable" do
118
- thing = Flipper::Types::Boolean.new
118
+ thing = Flipper::Types::Actor.new(Struct.new(:flipper_id).new("1"))
119
119
  gate = subject.gate_for(thing)
120
120
 
121
121
  subject.enable(thing)
@@ -129,6 +129,17 @@ describe Flipper::Feature do
129
129
  event.payload[:result].should_not be_nil
130
130
  end
131
131
 
132
+ it "always instruments flipper type instance for enable" do
133
+ thing = Struct.new(:flipper_id).new("1")
134
+ gate = subject.gate_for(thing)
135
+
136
+ subject.enable(thing)
137
+
138
+ event = instrumenter.events.last
139
+ event.should_not be_nil
140
+ event.payload[:thing].should eq(Flipper::Types::Actor.new(thing))
141
+ end
142
+
132
143
  it "is recorded for disable" do
133
144
  thing = Flipper::Types::Boolean.new
134
145
  gate = subject.gate_for(thing)
@@ -144,8 +155,50 @@ describe Flipper::Feature do
144
155
  event.payload[:result].should_not be_nil
145
156
  end
146
157
 
158
+ user = Struct.new(:flipper_id).new("1")
159
+ actor = Flipper::Types::Actor.new(user)
160
+ boolean_true = Flipper::Types::Boolean.new(true)
161
+ boolean_false = Flipper::Types::Boolean.new(false)
162
+ group = Flipper::Types::Group.new(:admins)
163
+ percentage_of_time = Flipper::Types::PercentageOfTime.new(10)
164
+ percentage_of_actors = Flipper::Types::PercentageOfActors.new(10)
165
+ {
166
+ user => actor,
167
+ actor => actor,
168
+ true => boolean_true,
169
+ false => boolean_false,
170
+ boolean_true => boolean_true,
171
+ boolean_false => boolean_false,
172
+ :admins => group,
173
+ group => group,
174
+ percentage_of_time => percentage_of_time,
175
+ percentage_of_actors => percentage_of_actors,
176
+ }.each do |thing, wrapped_thing|
177
+ it "always instruments #{thing.inspect} as #{wrapped_thing.class} for enable" do
178
+ Flipper.register(:admins) {}
179
+ subject.enable(thing)
180
+
181
+ event = instrumenter.events.last
182
+ event.should_not be_nil
183
+ event.payload[:operation].should eq(:enable)
184
+ event.payload[:thing].should eq(wrapped_thing)
185
+ end
186
+ end
187
+
188
+ it "always instruments flipper type instance for disable" do
189
+ thing = Struct.new(:flipper_id).new("1")
190
+ gate = subject.gate_for(thing)
191
+
192
+ subject.disable(thing)
193
+
194
+ event = instrumenter.events.last
195
+ event.should_not be_nil
196
+ event.payload[:operation].should eq(:disable)
197
+ event.payload[:thing].should eq(Flipper::Types::Actor.new(thing))
198
+ end
199
+
147
200
  it "is recorded for enabled?" do
148
- thing = Flipper::Types::Boolean.new
201
+ thing = Flipper::Types::Actor.new(Struct.new(:flipper_id).new("1"))
149
202
  gate = subject.gate_for(thing)
150
203
 
151
204
  subject.enabled?(thing)
@@ -158,6 +211,23 @@ describe Flipper::Feature do
158
211
  event.payload[:thing].should eq(thing)
159
212
  event.payload[:result].should eq(false)
160
213
  end
214
+
215
+ user = Struct.new(:flipper_id).new("1")
216
+ actor = Flipper::Types::Actor.new(user)
217
+ {
218
+ nil => nil,
219
+ user => actor,
220
+ actor => actor,
221
+ }.each do |thing, wrapped_thing|
222
+ it "always instruments #{thing.inspect} as #{wrapped_thing.class} for enabled?" do
223
+ subject.enabled?(thing)
224
+
225
+ event = instrumenter.events.last
226
+ event.should_not be_nil
227
+ event.payload[:operation].should eq(:enabled?)
228
+ event.payload[:thing].should eq(wrapped_thing)
229
+ end
230
+ end
161
231
  end
162
232
 
163
233
  describe "#state" do
@@ -31,4 +31,27 @@ describe Flipper::Gates::Group do
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ describe "#wrap" do
36
+ it "returns group instance for symbol" do
37
+ group = Flipper.register(:admins) {}
38
+ subject.wrap(:admins).should eq(group)
39
+ end
40
+
41
+ it "returns group instance for group instance" do
42
+ group = Flipper.register(:admins) {}
43
+ subject.wrap(group).should eq(group)
44
+ end
45
+ end
46
+
47
+ describe "#protects?" do
48
+ it "returns true for group" do
49
+ group = Flipper.register(:admins) {}
50
+ subject.protects?(group).should be(true)
51
+ end
52
+
53
+ it "returns true for symbol" do
54
+ subject.protects?(:admins).should be(true)
55
+ end
56
+ end
34
57
  end
@@ -50,7 +50,7 @@ describe Flipper::Instrumentation::LogSubscriber do
50
50
  end
51
51
 
52
52
  context "feature enabled checks with a thing" do
53
- let(:user) { Struct.new(:flipper_id).new('1') }
53
+ let(:user) { Flipper::Types::Actor.new(Struct.new(:flipper_id).new('1')) }
54
54
 
55
55
  before do
56
56
  clear_logs
@@ -69,7 +69,7 @@ describe Flipper::Instrumentation::LogSubscriber do
69
69
  end
70
70
 
71
71
  context "changing feature enabled state" do
72
- let(:user) { Struct.new(:flipper_id).new('1') }
72
+ let(:user) { Flipper::Types::Actor.new(Struct.new(:flipper_id).new('1')) }
73
73
 
74
74
  before do
75
75
  clear_logs
@@ -87,6 +87,12 @@ describe Flipper::Types::Actor do
87
87
  actor.admin?.should eq(true)
88
88
  end
89
89
 
90
+ it "exposes thing" do
91
+ thing = thing_class.new(10)
92
+ actor = described_class.new(thing)
93
+ actor.thing.should be(thing)
94
+ end
95
+
90
96
  describe "#respond_to?" do
91
97
  it "returns true if responds to method" do
92
98
  thing = thing_class.new('1')
@@ -10,7 +10,7 @@ module SpecHelpers
10
10
 
11
11
  def build_app(flipper)
12
12
  Flipper::UI.app(flipper) { |builder|
13
- builder.use Rack::Session::Cookie
13
+ builder.use Rack::Session::Cookie, secret: "test"
14
14
  }
15
15
  end
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.beta5
4
+ version: 0.7.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Feature flipper is the act of enabling/disabling features in your application,
14
14
  ideally without re-deploying or changing anything in your code base. Flipper makes
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: 1.3.1
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.2.2
132
+ rubygems_version: 2.2.3
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Feature flipper for ANYTHING