flip-flop 0.0.3 → 0.0.5
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 +4 -4
- data/.rspec +1 -0
- data/Gemfile.lock +2 -2
- data/README.md +32 -1
- data/lib/flip-flop.rb +5 -4
- data/lib/flip-flop/adapters/active_record.rb +3 -3
- data/lib/flip-flop/gates.rb +13 -9
- data/lib/flip-flop/group.rb +19 -0
- data/lib/flip-flop/version.rb +2 -2
- data/lib/flip-flop/view_helpers.rb +2 -2
- data/spec/lib/adapters/yaml_spec.rb +14 -2
- data/spec/lib/view_helpers_spec.rb +24 -0
- data/spec/test-config.yml +4 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acc3152ed4ebd7b39e858887a7c13c5db472bec2
|
|
4
|
+
data.tar.gz: 5f57534081e131d55c7602534cbfeacacc04b261
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fc793de8e5a677db5c9e0bb0b73931ec212753959b6b6c126926cf78a0741b50a797bfe833b41e4bdcd7edbc09a925021fa8811fe4069c1f59923e38cb77b1d
|
|
7
|
+
data.tar.gz: 16a9c9d267af5fd68348bc2109b5f498279c159860a0d519b6ccde14e0e5156188f7d2ec7e2b7a4cec14de349260998ddce572e7e6d83e3d29afb53e7e38bf31
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -62,9 +62,12 @@ for example:
|
|
|
62
62
|
:value: :production
|
|
63
63
|
:another_rails_env_example:
|
|
64
64
|
:type: :rails_env
|
|
65
|
-
:
|
|
65
|
+
:value:
|
|
66
66
|
- :production
|
|
67
67
|
- :test
|
|
68
|
+
:group_example:
|
|
69
|
+
:type: :group
|
|
70
|
+
:value: :group_name
|
|
68
71
|
```
|
|
69
72
|
|
|
70
73
|
Example Usage
|
|
@@ -118,6 +121,34 @@ Gates
|
|
|
118
121
|
* `time_range` — enable a feature for the duration of a time range
|
|
119
122
|
* `percentage_of_time` — enable a feature for a given percentage of checks
|
|
120
123
|
* `rails_env` — enable a feature for a specified Rails environment
|
|
124
|
+
* `group` — enable a feature for a specified group of users (needs additional configuration)
|
|
125
|
+
|
|
126
|
+
Groups
|
|
127
|
+
------
|
|
128
|
+
|
|
129
|
+
To use the group adapter you need to register a group. For Ruby on Rails this can be done in an initializer.
|
|
130
|
+
Groups are reusable, many features can be tied to a single group.
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
FlipFlop::Group.register(:administrators) do |user|
|
|
134
|
+
user.is_admin?
|
|
135
|
+
end
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Setup your feature definition. Here is an example using the YAML adapter:
|
|
139
|
+
|
|
140
|
+
```yaml
|
|
141
|
+
---
|
|
142
|
+
:awesome_admin_only_feature
|
|
143
|
+
:type: :group
|
|
144
|
+
:value: :administrators
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
When checking if the feature is enabled for that group you can provide the actor (user).
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
FlipFlop.feature_enabled? :awesome_admin_only_feature, user
|
|
151
|
+
```
|
|
121
152
|
|
|
122
153
|
Adapters
|
|
123
154
|
--------
|
data/lib/flip-flop.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'flip-flop/gates'
|
|
2
2
|
require 'flip-flop/adapters/memory'
|
|
3
3
|
require 'flip-flop/railtie' if defined? Rails
|
|
4
|
+
require 'flip-flop/group'
|
|
4
5
|
|
|
5
6
|
module FlipFlop
|
|
6
7
|
|
|
@@ -32,8 +33,8 @@ module FlipFlop
|
|
|
32
33
|
#
|
|
33
34
|
# Arguments:
|
|
34
35
|
# feature_name (String/Symbol)
|
|
35
|
-
def self.feature_enabled?(feature_name)
|
|
36
|
-
get_instance.feature_enabled? feature_name.to_sym
|
|
36
|
+
def self.feature_enabled?(feature_name, actor=nil)
|
|
37
|
+
get_instance.feature_enabled? feature_name.to_sym, actor
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
class FlipFlop
|
|
@@ -63,8 +64,8 @@ module FlipFlop
|
|
|
63
64
|
#
|
|
64
65
|
# Returns:
|
|
65
66
|
# boolean
|
|
66
|
-
def feature_enabled?(feature_name)
|
|
67
|
-
public_send feature_type(feature_name), feature_value(feature_name)
|
|
67
|
+
def feature_enabled?(feature_name, actor=nil)
|
|
68
|
+
public_send feature_type(feature_name), feature_value(feature_name), actor
|
|
68
69
|
rescue
|
|
69
70
|
false
|
|
70
71
|
end
|
|
@@ -6,9 +6,9 @@ module FlipFlop
|
|
|
6
6
|
|
|
7
7
|
# override this method to prevent the feature being loaded from the
|
|
8
8
|
# database twice.
|
|
9
|
-
def feature_enabled?(feature_name)
|
|
9
|
+
def feature_enabled?(feature_name, actor=nil)
|
|
10
10
|
f = get_feature(feature_name)
|
|
11
|
-
public_send f.gate_type, f.value
|
|
11
|
+
public_send f.gate_type, f.value, actor
|
|
12
12
|
rescue
|
|
13
13
|
false
|
|
14
14
|
end
|
|
@@ -54,7 +54,7 @@ module FlipFlop
|
|
|
54
54
|
def gate_type
|
|
55
55
|
super.to_sym
|
|
56
56
|
end
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
end
|
data/lib/flip-flop/gates.rb
CHANGED
|
@@ -2,40 +2,44 @@ require 'date'
|
|
|
2
2
|
|
|
3
3
|
module FlipFlop
|
|
4
4
|
module Gates
|
|
5
|
-
def boolean(value)
|
|
5
|
+
def boolean(value, actor)
|
|
6
6
|
value
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def date_range(value)
|
|
9
|
+
def date_range(value, actor)
|
|
10
10
|
value.begin < Date.today && value.end > Date.today
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def until_date(value)
|
|
13
|
+
def until_date(value, actor)
|
|
14
14
|
Date.today < value
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def after_date(value)
|
|
17
|
+
def after_date(value, actor)
|
|
18
18
|
Date.today > value
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def time_range(value)
|
|
21
|
+
def time_range(value, actor)
|
|
22
22
|
value.begin < Time.now.utc && value.end > Time.now.utc
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def until_time(value)
|
|
25
|
+
def until_time(value, actor)
|
|
26
26
|
Time.now.utc < value
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def after_time(value)
|
|
29
|
+
def after_time(value, actor)
|
|
30
30
|
Time.now.utc > value
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def percentage_of_time(value)
|
|
33
|
+
def percentage_of_time(value, actor)
|
|
34
34
|
rand < (value / 100.0)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def rails_env(value)
|
|
37
|
+
def rails_env(value, actor)
|
|
38
38
|
value == Rails.env.to_sym || value.include?(Rails.env.to_sym)
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
def group(group_name, actor)
|
|
42
|
+
Group.evaluate_group(group_name, actor)
|
|
43
|
+
end
|
|
40
44
|
end
|
|
41
45
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module FlipFlop
|
|
2
|
+
|
|
3
|
+
class Group
|
|
4
|
+
|
|
5
|
+
@@groups = {}
|
|
6
|
+
|
|
7
|
+
def self.register group_name, &block
|
|
8
|
+
@@groups[group_name] = block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.evaluate_group group_name, actor
|
|
12
|
+
@@groups[group_name].call actor
|
|
13
|
+
rescue
|
|
14
|
+
false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
data/lib/flip-flop/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module FlipFlop
|
|
2
|
-
VERSION = '0.0.
|
|
3
|
-
end
|
|
2
|
+
VERSION = '0.0.5'
|
|
3
|
+
end
|
|
@@ -12,8 +12,20 @@ describe FlipFlop do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'should load from yaml file' do
|
|
15
|
-
expect(FlipFlop
|
|
16
|
-
expect(FlipFlop
|
|
15
|
+
expect(FlipFlop.feature_enabled? :on).to be_truthy
|
|
16
|
+
expect(FlipFlop.feature_enabled? :off).to be_falsey
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'should still work for group gate' do
|
|
20
|
+
user1 = { group: "a" }
|
|
21
|
+
user2 = { group: "b" }
|
|
22
|
+
|
|
23
|
+
FlipFlop::Group.register(:group_name) do |actor|
|
|
24
|
+
actor[:group] == 'a'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
expect(FlipFlop.feature_enabled? :group_example, user1).to be_truthy
|
|
28
|
+
expect(FlipFlop.feature_enabled? :group_example, user2).to be_falsey
|
|
17
29
|
end
|
|
18
30
|
|
|
19
31
|
end
|
|
@@ -150,4 +150,28 @@ describe DummyController do
|
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
+
context 'group gate' do
|
|
154
|
+
before :each do
|
|
155
|
+
::FlipFlop::Group.register(:group_a) { |actor| actor[:user_group] == 'asdf' }
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'should be able to execute logic specified when registering a group' do
|
|
159
|
+
::FlipFlop::get_instance.set_feature(:awesomeness, :group, :group_a)
|
|
160
|
+
actor = { user_group: 'asdf' }
|
|
161
|
+
expect(subject.feature_enabled? :awesomeness, actor).to be_truthy
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'should fail the feature check if the block doesnt pass' do
|
|
165
|
+
::FlipFlop::get_instance.set_feature(:awesomeness, :group, :group_a)
|
|
166
|
+
actor = { user_group: 'qwert' }
|
|
167
|
+
expect(subject.feature_enabled? :awesomeness, actor).to be_falsey
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'should fail if the group has not been defined' do
|
|
171
|
+
::FlipFlop::get_instance.set_feature(:awesomeness, :group, :group_b)
|
|
172
|
+
actor = { user_group: 'not_there' }
|
|
173
|
+
expect(subject.feature_enabled? :awesomeness, actor).to be_falsey
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
153
177
|
end
|
data/spec/test-config.yml
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flip-flop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Kulyk
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Enable or disable features easily
|
|
14
14
|
email:
|
|
@@ -17,6 +17,7 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- ".rspec"
|
|
20
21
|
- Gemfile
|
|
21
22
|
- Gemfile.lock
|
|
22
23
|
- README.md
|
|
@@ -27,6 +28,7 @@ files:
|
|
|
27
28
|
- lib/flip-flop/adapters/memory.rb
|
|
28
29
|
- lib/flip-flop/adapters/yaml.rb
|
|
29
30
|
- lib/flip-flop/gates.rb
|
|
31
|
+
- lib/flip-flop/group.rb
|
|
30
32
|
- lib/flip-flop/railtie.rb
|
|
31
33
|
- lib/flip-flop/version.rb
|
|
32
34
|
- lib/flip-flop/view_helpers.rb
|
|
@@ -57,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
59
|
version: '0'
|
|
58
60
|
requirements: []
|
|
59
61
|
rubyforge_project:
|
|
60
|
-
rubygems_version: 2.
|
|
62
|
+
rubygems_version: 2.4.8
|
|
61
63
|
signing_key:
|
|
62
64
|
specification_version: 4
|
|
63
65
|
summary: Feature flipper
|