flipper-echo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +1 -0
- data/flipper-echo.gemspec +30 -0
- data/lib/flipper/echo.rb +61 -0
- data/lib/flipper/echo/configuration.rb +36 -0
- data/lib/flipper/echo/event.rb +101 -0
- data/lib/flipper/echo/version.rb +9 -0
- data/spec/flipper/echo/configuration_spec.rb +33 -0
- data/spec/flipper/echo/event_spec.rb +177 -0
- data/spec/flipper/echo/version_spec.rb +0 -0
- data/spec/flipper/echo_spec.rb +83 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/adapter_support.rb +11 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d0193b01d3747866567392b00529405385d4b23
|
4
|
+
data.tar.gz: 03d2d537df9c51aca849cc279245dd39f63835cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 361febaf3cf8772c5eb2f723a3896068c00588e9f6e2aaf2003d3a52fb00a65356ba0dd3c94fb70b08767bfacdf3dd209e5f1e649140c95ec3b7b0b35d355982
|
7
|
+
data.tar.gz: 94c0a649e23ff84a9b9c41fce70c1145c3a24a9222377c073e237c4fae93ceabb7a12f1fa82cfdd4f8594d2a21c89d220e80f11256eb57c01c39b26ad25ea378
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Heather Rivers
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Flipper::Echo
|
2
|
+
|
3
|
+
This gem adds a simple callback interface for
|
4
|
+
[Flipper](https://github.com/jnunemaker/flipper) adapter events.
|
5
|
+
|
6
|
+
For example, when a Flipper feature is changed, you can:
|
7
|
+
|
8
|
+
* send a Slack notification
|
9
|
+
* write the change to a database or log file
|
10
|
+
* send a YO
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'flipper-echo'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install flipper-echo
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
First, [configure Flipper](https://github.com/jnunemaker/flipper#usage) as you
|
31
|
+
normally would (any adapter will do), e.g.:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
FLIPPER = Flipper.new(Flipper::Adapters::Memory.new)
|
35
|
+
```
|
36
|
+
|
37
|
+
Then configure `Flipper::Echo`:
|
38
|
+
|
39
|
+
#### Option 1: handle event with a proc
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Flipper::Echo.configure do |config|
|
43
|
+
config.flipper = FLIPPER
|
44
|
+
|
45
|
+
config.notifier = proc do |event|
|
46
|
+
# Do something with the event...
|
47
|
+
#
|
48
|
+
puts "#{event.feature.name} changed: #{event.action}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Option 2: handle event with a notifier class
|
54
|
+
|
55
|
+
`Flipper::Echo` can also use any object that has a `notify` method:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class FlipperNotifier
|
59
|
+
def notify(event)
|
60
|
+
# Do something with the event...
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Flipper::Echo.configure do |config|
|
65
|
+
config.flipper = FLIPPER
|
66
|
+
config.notifier = FlipperNotifier.new
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( https://github.com/mode/flipper-echo/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flipper/echo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'flipper-echo'
|
8
|
+
spec.version = Flipper::Echo::VERSION
|
9
|
+
spec.authors = ['Heather Rivers']
|
10
|
+
spec.email = ['heather@modeanalytics.com']
|
11
|
+
spec.summary = 'Flipper event notifier'
|
12
|
+
spec.description = 'Extensible event notifier for Flipper gem'
|
13
|
+
spec.homepage = 'https://github.com/mode/flipper-echo'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '~> 2.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'flipper', '~> 0.6'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
30
|
+
end
|
data/lib/flipper/echo.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'flipper/echo/configuration'
|
4
|
+
require 'flipper/echo/event'
|
5
|
+
require 'flipper/echo/version'
|
6
|
+
|
7
|
+
# Flipper namespace
|
8
|
+
#
|
9
|
+
module Flipper
|
10
|
+
# Echo namespace
|
11
|
+
#
|
12
|
+
module Echo
|
13
|
+
class << self
|
14
|
+
# Yield configuration instance for modification
|
15
|
+
#
|
16
|
+
def configure
|
17
|
+
yield configuration if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Configuration instance
|
21
|
+
#
|
22
|
+
def configuration
|
23
|
+
@configuration ||= Flipper::Echo::Configuration.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Instance methods to be included in the adapter's singleton class
|
28
|
+
#
|
29
|
+
module InstanceMethods
|
30
|
+
# Notify adapter enable events
|
31
|
+
#
|
32
|
+
def enable(feature, gate, target)
|
33
|
+
super.tap do
|
34
|
+
Flipper::Echo::Event.new(
|
35
|
+
feature, :enable, gate: gate, target: target).notify
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Notify adapter disable events
|
40
|
+
#
|
41
|
+
def disable(feature, gate, target)
|
42
|
+
super.tap do
|
43
|
+
Flipper::Echo::Event.new(
|
44
|
+
feature, :disable, gate: gate, target: target).notify
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Notify adapter remove events
|
49
|
+
#
|
50
|
+
def remove(feature)
|
51
|
+
super.tap { Flipper::Echo::Event.new(feature, :remove).notify }
|
52
|
+
end
|
53
|
+
|
54
|
+
# Notify adapter clear events
|
55
|
+
#
|
56
|
+
def clear(feature)
|
57
|
+
super.tap { Flipper::Echo::Event.new(feature, :clear).notify }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
module Flipper
|
4
|
+
module Echo
|
5
|
+
# General configuration class
|
6
|
+
#
|
7
|
+
# If `notifier` is not assigned, notification events will not be sent.
|
8
|
+
#
|
9
|
+
# Only one of `#flipper=` or `#adapter=`, as preferred, must be called for
|
10
|
+
# intended behavior.
|
11
|
+
#
|
12
|
+
class Configuration
|
13
|
+
attr_accessor :notifier
|
14
|
+
|
15
|
+
# Assign Flipper instance
|
16
|
+
#
|
17
|
+
# @param flipper [Flipper::DSL] the Flipper instance
|
18
|
+
#
|
19
|
+
# @return [Class] the adapter singleton class
|
20
|
+
#
|
21
|
+
def flipper=(flipper)
|
22
|
+
self.adapter = flipper.adapter
|
23
|
+
end
|
24
|
+
|
25
|
+
# Assign Flipper adapter instance
|
26
|
+
#
|
27
|
+
# @param adapter [Flipper::Adapter] the Flipper adapter instance
|
28
|
+
#
|
29
|
+
# @return [Class] the adapter singleton class
|
30
|
+
#
|
31
|
+
def adapter=(adapter)
|
32
|
+
adapter.singleton_class.include Flipper::Echo::InstanceMethods
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
module Flipper
|
4
|
+
module Echo
|
5
|
+
# Encapsulates relevant information about a Flipper adapter event
|
6
|
+
#
|
7
|
+
class Event
|
8
|
+
attr_reader :feature, :action, :options
|
9
|
+
|
10
|
+
# Construct a new Event instance
|
11
|
+
#
|
12
|
+
# @param feature [Flipper::Feature] the feature that was changed
|
13
|
+
# @param action [Symbol] the action
|
14
|
+
# (`:enable`, `:disable`, `:remove` or `:clear`)
|
15
|
+
# @param options [optional, Hash] hash of options
|
16
|
+
#
|
17
|
+
# @option options [Flipper::Type] :target the event target
|
18
|
+
# @option options [Flipper::Gate] :gate the event gate
|
19
|
+
#
|
20
|
+
# @return [Flipper::Echo::Event] the instance
|
21
|
+
#
|
22
|
+
def initialize(feature, action, options = {})
|
23
|
+
@feature = feature
|
24
|
+
@action = action
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
# Boolean target
|
29
|
+
#
|
30
|
+
# @return [Flipper::Types::Boolean, nil]
|
31
|
+
#
|
32
|
+
def boolean
|
33
|
+
target if target.is_a?(Flipper::Types::Boolean)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Group target
|
37
|
+
#
|
38
|
+
# @return [Flipper::Types::Group, nil]
|
39
|
+
#
|
40
|
+
def group
|
41
|
+
target if target.is_a?(Flipper::Types::Group)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Actor target
|
45
|
+
#
|
46
|
+
# @return [Flipper::Types::Actor, nil]
|
47
|
+
#
|
48
|
+
def actor
|
49
|
+
target if target.is_a?(Flipper::Types::Actor)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Percentage of actors target
|
53
|
+
#
|
54
|
+
# @return [Flipper::Types::PercentageOfActors, nil]
|
55
|
+
#
|
56
|
+
def percentage_of_actors
|
57
|
+
target if target.is_a?(Flipper::Types::PercentageOfActors)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Percentage of random target
|
61
|
+
#
|
62
|
+
# @return [Flipper::Types::PercentageOfRandom, nil]
|
63
|
+
#
|
64
|
+
def percentage_of_random
|
65
|
+
target if target.is_a?(Flipper::Types::PercentageOfRandom)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Passes this event to the configured notifier
|
69
|
+
#
|
70
|
+
def notify
|
71
|
+
if notifier.is_a?(Proc)
|
72
|
+
notifier.call(self)
|
73
|
+
elsif notifier.respond_to?(:notify)
|
74
|
+
notifier.notify(self)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# The event target, if any
|
79
|
+
#
|
80
|
+
# @return [Flipper::Type]
|
81
|
+
#
|
82
|
+
def target
|
83
|
+
options[:target]
|
84
|
+
end
|
85
|
+
|
86
|
+
# The event gate, if any
|
87
|
+
#
|
88
|
+
# @return [Flipper::Gate]
|
89
|
+
#
|
90
|
+
def gate
|
91
|
+
options[:gate]
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def notifier
|
97
|
+
Flipper::Echo.configuration.notifier
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Flipper::Echo::Configuration do
|
6
|
+
let :adapter do
|
7
|
+
adapter_class.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let :flipper do
|
11
|
+
double(:flipper, adapter: adapter)
|
12
|
+
end
|
13
|
+
|
14
|
+
let :configuration do
|
15
|
+
Flipper::Echo::Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#adapter=' do
|
19
|
+
it 'assigns adapter' do
|
20
|
+
expect(adapter.singleton_class).to receive(:include)
|
21
|
+
|
22
|
+
configuration.adapter = adapter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#flipper=' do
|
27
|
+
it 'assigns adapter' do
|
28
|
+
expect(adapter.singleton_class).to receive(:include)
|
29
|
+
|
30
|
+
configuration.flipper = flipper
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'flipper'
|
5
|
+
|
6
|
+
describe Flipper::Echo::Event do
|
7
|
+
let :feature do
|
8
|
+
double(:feature)
|
9
|
+
end
|
10
|
+
|
11
|
+
let :action do
|
12
|
+
double(:action)
|
13
|
+
end
|
14
|
+
|
15
|
+
let :group do
|
16
|
+
Flipper::Types::Group.new(:dummy)
|
17
|
+
end
|
18
|
+
|
19
|
+
let :boolean do
|
20
|
+
Flipper::Types::Boolean.new
|
21
|
+
end
|
22
|
+
|
23
|
+
let :actor do
|
24
|
+
Flipper::Types::Actor.new(double(:actor, flipper_id: nil))
|
25
|
+
end
|
26
|
+
|
27
|
+
let :percentage_of_actors do
|
28
|
+
Flipper::Types::PercentageOfActors.new(nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
let :percentage_of_random do
|
32
|
+
Flipper::Types::PercentageOfRandom.new(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#boolean' do
|
36
|
+
it 'returns nil if target type does not match' do
|
37
|
+
event = Flipper::Echo::Event.new(feature, action, target: group)
|
38
|
+
|
39
|
+
expect(event.boolean).to eq(nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns target if target type matches' do
|
43
|
+
event = Flipper::Echo::Event.new(feature, action, target: boolean)
|
44
|
+
|
45
|
+
expect(event.boolean).to eq(boolean)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#group' do
|
50
|
+
it 'returns nil if target type does not match' do
|
51
|
+
event = Flipper::Echo::Event.new(feature, action, target: boolean)
|
52
|
+
|
53
|
+
expect(event.group).to eq(nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns target if target type matches' do
|
57
|
+
event = Flipper::Echo::Event.new(feature, action, target: group)
|
58
|
+
|
59
|
+
expect(event.group).to eq(group)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#actor' do
|
64
|
+
it 'returns nil if target type does not match' do
|
65
|
+
event = Flipper::Echo::Event.new(feature, action, target: boolean)
|
66
|
+
|
67
|
+
expect(event.actor).to eq(nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns target if target type matches' do
|
71
|
+
event = Flipper::Echo::Event.new(feature, action, target: actor)
|
72
|
+
|
73
|
+
expect(event.actor).to eq(actor)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#percentage_of_actors' do
|
78
|
+
it 'returns nil if target type does not match' do
|
79
|
+
event = Flipper::Echo::Event.new(feature, action, target: boolean)
|
80
|
+
|
81
|
+
expect(event.percentage_of_actors).to eq(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns target if target type matches' do
|
85
|
+
event = Flipper::Echo::Event.new(
|
86
|
+
feature, action, target: percentage_of_actors)
|
87
|
+
|
88
|
+
expect(event.percentage_of_actors).to eq(percentage_of_actors)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#percentage_of_random' do
|
93
|
+
it 'returns nil if target type does not match' do
|
94
|
+
event = Flipper::Echo::Event.new(feature, action, target: boolean)
|
95
|
+
|
96
|
+
expect(event.percentage_of_random).to eq(nil)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns target if target type matches' do
|
100
|
+
event = Flipper::Echo::Event.new(
|
101
|
+
feature, action, target: percentage_of_random)
|
102
|
+
|
103
|
+
expect(event.percentage_of_random).to eq(percentage_of_random)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#gate' do
|
108
|
+
it 'returns gate from options' do
|
109
|
+
gate = double(:gate)
|
110
|
+
|
111
|
+
event = Flipper::Echo::Event.new(feature, action, gate: gate)
|
112
|
+
|
113
|
+
expect(event.gate).to eq(gate)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#notify' do
|
118
|
+
let :event do
|
119
|
+
Flipper::Echo::Event.new(feature, action)
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'when notifier is a proc' do
|
123
|
+
it 'calls proc' do
|
124
|
+
procedure = proc {}
|
125
|
+
|
126
|
+
allow(event).to receive(:notifier).and_return(procedure)
|
127
|
+
|
128
|
+
expect(procedure).to receive(:call)
|
129
|
+
|
130
|
+
event.notify
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'when notifier is a non proc object' do
|
135
|
+
let :notifier do
|
136
|
+
double(:notifier)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'calls instance method if it exists' do
|
140
|
+
allow(event).to receive(:notifier).and_return(notifier)
|
141
|
+
|
142
|
+
expect(notifier).to receive(:notify)
|
143
|
+
|
144
|
+
event.notify
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'does nothing if method does not exist' do
|
148
|
+
allow(event).to receive(:notifier).and_return(notifier)
|
149
|
+
|
150
|
+
event.notify
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'when notifier is nil' do
|
155
|
+
it 'does nothing' do
|
156
|
+
allow(event).to receive(:notifier).and_return(nil)
|
157
|
+
|
158
|
+
event.notify
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#notifier' do
|
164
|
+
let :notifier do
|
165
|
+
double(:notifier)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'returns notifier from config' do
|
169
|
+
allow(Flipper::Echo.configuration).to(
|
170
|
+
receive(:notifier).and_return(notifier))
|
171
|
+
|
172
|
+
event = Flipper::Echo::Event.new(feature, action)
|
173
|
+
|
174
|
+
expect(event.send(:notifier)).to eq(notifier)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
File without changes
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Flipper::Echo do
|
6
|
+
describe '.configure' do
|
7
|
+
it 'sets configuration variables' do
|
8
|
+
expect_any_instance_of(
|
9
|
+
Flipper::Echo::Configuration).to receive(:setting=).once
|
10
|
+
|
11
|
+
Flipper::Echo.configure do |config|
|
12
|
+
config.setting = 'value'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.configuration' do
|
18
|
+
it 'is a configuration instance' do
|
19
|
+
expect(Flipper::Echo.configuration).to(
|
20
|
+
be_an_instance_of(Flipper::Echo::Configuration))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Flipper::Echo::InstanceMethods do
|
25
|
+
let :adapter do
|
26
|
+
adapter_class.new.tap do |inst|
|
27
|
+
inst.singleton_class.include Flipper::Echo::InstanceMethods
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let :feature do
|
32
|
+
double(:feature)
|
33
|
+
end
|
34
|
+
|
35
|
+
let :gate do
|
36
|
+
double(:gate)
|
37
|
+
end
|
38
|
+
|
39
|
+
let :target do
|
40
|
+
double(:target)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#enable' do
|
44
|
+
it 'enables feature' do
|
45
|
+
expect_any_instance_of(Flipper::Echo::Event).to receive(:notify) do |e|
|
46
|
+
expect(e.action).to eq(:enable)
|
47
|
+
end
|
48
|
+
|
49
|
+
adapter.enable(feature, gate, target)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#disable' do
|
54
|
+
it 'disables feature' do
|
55
|
+
expect_any_instance_of(Flipper::Echo::Event).to receive(:notify) do |e|
|
56
|
+
expect(e.action).to eq(:disable)
|
57
|
+
end
|
58
|
+
|
59
|
+
adapter.disable(feature, gate, target)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#remove' do
|
64
|
+
it 'removes feature' do
|
65
|
+
expect_any_instance_of(Flipper::Echo::Event).to receive(:notify) do |e|
|
66
|
+
expect(e.action).to eq(:remove)
|
67
|
+
end
|
68
|
+
|
69
|
+
adapter.remove(feature)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#clear' do
|
74
|
+
it 'clears feature' do
|
75
|
+
expect_any_instance_of(Flipper::Echo::Event).to receive(:notify) do |e|
|
76
|
+
expect(e.action).to eq(:clear)
|
77
|
+
end
|
78
|
+
|
79
|
+
adapter.clear(feature)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler.setup
|
8
|
+
|
9
|
+
require 'flipper/echo'
|
10
|
+
|
11
|
+
Dir['./spec/support/**/*.rb'].each(&method(:require))
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include AdapterSupport
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flipper-echo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Heather Rivers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flipper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
description: Extensible event notifier for Flipper gem
|
98
|
+
email:
|
99
|
+
- heather@modeanalytics.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- flipper-echo.gemspec
|
110
|
+
- lib/flipper/echo.rb
|
111
|
+
- lib/flipper/echo/configuration.rb
|
112
|
+
- lib/flipper/echo/event.rb
|
113
|
+
- lib/flipper/echo/version.rb
|
114
|
+
- spec/flipper/echo/configuration_spec.rb
|
115
|
+
- spec/flipper/echo/event_spec.rb
|
116
|
+
- spec/flipper/echo/version_spec.rb
|
117
|
+
- spec/flipper/echo_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/support/adapter_support.rb
|
120
|
+
homepage: https://github.com/mode/flipper-echo
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '2.0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.2.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Flipper event notifier
|
144
|
+
test_files:
|
145
|
+
- spec/flipper/echo/configuration_spec.rb
|
146
|
+
- spec/flipper/echo/event_spec.rb
|
147
|
+
- spec/flipper/echo/version_spec.rb
|
148
|
+
- spec/flipper/echo_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/support/adapter_support.rb
|
151
|
+
has_rdoc:
|