toggles 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/features/{test.yml → multiple_subjects.yml} +0 -0
- data/features/type.yml +6 -0
- data/lib/toggles/feature.rb +8 -8
- data/lib/toggles/feature/operation.rb +8 -0
- data/lib/toggles/feature/operation/and.rb +11 -0
- data/lib/toggles/feature/operation/attribute.rb +19 -0
- data/lib/toggles/feature/operation/gt.rb +9 -0
- data/lib/toggles/feature/operation/in.rb +15 -0
- data/lib/toggles/feature/operation/lt.rb +9 -0
- data/lib/toggles/feature/operation/not.rb +15 -0
- data/lib/toggles/feature/operation/or.rb +11 -0
- data/lib/toggles/feature/operation/range.rb +10 -0
- data/lib/toggles/feature/permissions.rb +9 -4
- data/spec/toggles/feature/acceptance/collection_spec.rb +9 -0
- data/spec/toggles/feature/acceptance/multiple_subjects_spec.rb +17 -0
- data/spec/toggles/feature/acceptance/nested_attributes_spec.rb +13 -0
- data/spec/toggles/feature/acceptance/type_spec.rb +6 -0
- data/spec/toggles/feature/base_spec.rb +1 -24
- data/spec/toggles/feature/{permissions/operation → operation}/and_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/attribute_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/gt_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/in_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/lt_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/not_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/or_spec.rb +1 -1
- data/spec/toggles/feature/{permissions/operation → operation}/range_spec.rb +1 -1
- data/spec/toggles/feature/permissions_spec.rb +1 -1
- data/toggles.gemspec +1 -1
- metadata +37 -30
- data/lib/toggles/feature/permissions/operation.rb +0 -8
- data/lib/toggles/feature/permissions/operation/and.rb +0 -13
- data/lib/toggles/feature/permissions/operation/attribute.rb +0 -21
- data/lib/toggles/feature/permissions/operation/gt.rb +0 -11
- data/lib/toggles/feature/permissions/operation/in.rb +0 -17
- data/lib/toggles/feature/permissions/operation/lt.rb +0 -11
- data/lib/toggles/feature/permissions/operation/not.rb +0 -17
- data/lib/toggles/feature/permissions/operation/or.rb +0 -13
- data/lib/toggles/feature/permissions/operation/range.rb +0 -12
- data/spec/toggles/feature/nested_attributes_spec.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31164f56157983183da56700b347bb70a5373058
|
4
|
+
data.tar.gz: 9b258b42d5b7e8d7fdf95b91ec8c19ddfab5820f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f70ab0bda18fe55346c769b49eafcb1d67a7faf0e73eefbcf86686d8131fdc951ece6caf64f71722ab454211780b0525ab2fe6c2a6fdd781fe1ad87432adcae
|
7
|
+
data.tar.gz: fda41fa20f04da055008917544349718ca39b24ab6455e644651558f05cbcb5e50e5d85d2af73e8c2e47f33fd3881603e5776e0d6cfda4f979e6cb6f4f39d820
|
File without changes
|
data/features/type.yml
ADDED
data/lib/toggles/feature.rb
CHANGED
@@ -2,17 +2,17 @@ require "find"
|
|
2
2
|
|
3
3
|
require "toggles/feature/base"
|
4
4
|
require "toggles/feature/subject"
|
5
|
+
require "toggles/feature/operation"
|
5
6
|
require "toggles/feature/permissions"
|
6
|
-
require "toggles/feature/permissions/operation"
|
7
7
|
|
8
8
|
module Feature
|
9
|
-
OPERATIONS = {and:
|
10
|
-
gt:
|
11
|
-
in:
|
12
|
-
lt:
|
13
|
-
not:
|
14
|
-
or:
|
15
|
-
range:
|
9
|
+
OPERATIONS = {and: Operation::And,
|
10
|
+
gt: Operation::GreaterThan,
|
11
|
+
in: Operation::In,
|
12
|
+
lt: Operation::LessThan,
|
13
|
+
not: Operation::Not,
|
14
|
+
or: Operation::Or,
|
15
|
+
range: Operation::Range}
|
16
16
|
end
|
17
17
|
|
18
18
|
# Dynamically create modules and classes within the `Feature` module based on
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "toggles/feature/operation/and"
|
2
|
+
require "toggles/feature/operation/attribute"
|
3
|
+
require "toggles/feature/operation/gt"
|
4
|
+
require "toggles/feature/operation/in"
|
5
|
+
require "toggles/feature/operation/lt"
|
6
|
+
require "toggles/feature/operation/not"
|
7
|
+
require "toggles/feature/operation/or"
|
8
|
+
require "toggles/feature/operation/range"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Feature
|
2
|
+
module Operation
|
3
|
+
class Attribute
|
4
|
+
def self.call(entity, attr_name, expected)
|
5
|
+
if expected.kind_of? Hash
|
6
|
+
expected.all? do |operation, rules|
|
7
|
+
if OPERATIONS.include? operation.to_sym
|
8
|
+
OPERATIONS[operation.to_sym].call(entity, attr_name, rules)
|
9
|
+
else
|
10
|
+
Operation::Attribute.call(entity.send(attr_name), operation, rules)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
else
|
14
|
+
entity.send(attr_name) == expected
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Feature
|
2
|
+
module Operation
|
3
|
+
class In
|
4
|
+
def self.call(entity, attr_name, expected)
|
5
|
+
if expected.kind_of? Hash
|
6
|
+
expected = expected.reduce([]) do |list, (operation, args)|
|
7
|
+
OPERATIONS[operation.to_sym].call(args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
expected.include? entity.send(attr_name.to_sym)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Feature
|
2
|
+
module Operation
|
3
|
+
class Not
|
4
|
+
def self.call(entity, attr_name, expected)
|
5
|
+
if expected.kind_of? Hash
|
6
|
+
expected.none? do |operation, value|
|
7
|
+
OPERATIONS[operation.to_sym].call(entity, attr_name, value)
|
8
|
+
end
|
9
|
+
else
|
10
|
+
entity.send(attr_name) != expected
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "ostruct"
|
2
2
|
|
3
3
|
module Feature
|
4
4
|
class Permissions
|
@@ -22,10 +22,15 @@ module Feature
|
|
22
22
|
end
|
23
23
|
|
24
24
|
rules.all? do |name, rule|
|
25
|
+
entity = entities[name.to_sym]
|
26
|
+
|
27
|
+
if entity.class.ancestors.find { |ancestor| ancestor == Comparable }
|
28
|
+
entity = OpenStruct.new(name => entity)
|
29
|
+
rule = {name => rule}
|
30
|
+
end
|
31
|
+
|
25
32
|
rule.all? do |key, value|
|
26
|
-
OPERATIONS.fetch(key, Operation::Attribute).call(
|
27
|
-
entities[name.to_sym], key, value
|
28
|
-
)
|
33
|
+
OPERATIONS.fetch(key, Operation::Attribute).call(entity, key, value)
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe Feature::Collection do
|
2
|
+
specify do
|
3
|
+
expect(Feature::Collection.enabled_for?(user: double(id: 1))).to eq true
|
4
|
+
expect(Feature::Collection.enabled_for?(user: double(id: 5))).to eq true
|
5
|
+
expect(Feature::Collection.enabled_for?(user: double(id: 10))).to eq true
|
6
|
+
expect(Feature::Collection.enabled_for?(user: double(id: 49))).to eq false
|
7
|
+
expect(Feature::Collection.enabled_for?(user: double(id: 51))).to eq true
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe Feature::MultipleSubjects do
|
2
|
+
specify do
|
3
|
+
expect(Feature::MultipleSubjects.enabled_for?(
|
4
|
+
user: double(id: 1, logged_in?: true), widget: double(id: 2))).to eq true
|
5
|
+
|
6
|
+
expect(Feature::MultipleSubjects.enabled_for?(
|
7
|
+
user: double(id: 1, logged_in?: false), widget: double(id: 2))).to eq false
|
8
|
+
expect(Feature::MultipleSubjects.enabled_for?(
|
9
|
+
user: double(id: 1, logged_in?: true), widget: double(id: 3))).to eq false
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "invalid permissions" do
|
13
|
+
expect { Feature::MultipleSubjects.enabled_for?(widget: double) }.
|
14
|
+
to raise_error Feature::Subject::Invalid,
|
15
|
+
"Invalid or missing subjects for permissions: [:user]"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe Feature::NestedAttributes do
|
2
|
+
specify do
|
3
|
+
expect(Feature::NestedAttributes.enabled_for?(
|
4
|
+
foo: double(bar: :two, baz: double(id: 51)))).to eq true
|
5
|
+
expect(Feature::NestedAttributes.enabled_for?(
|
6
|
+
foo: double(bar: :two, baz: double(id: 10)))).to eq true
|
7
|
+
|
8
|
+
expect(Feature::NestedAttributes.enabled_for?(
|
9
|
+
foo: double(bar: :one, baz: double(id: 51)))).to eq false
|
10
|
+
expect(Feature::NestedAttributes.enabled_for?(
|
11
|
+
foo: double(bar: :two, baz: double(id: 50)))).to eq false
|
12
|
+
end
|
13
|
+
end
|
@@ -2,32 +2,9 @@ describe Feature::Base do
|
|
2
2
|
let(:user) { double(id: 1, logged_in?: true) }
|
3
3
|
let(:widget) { double(id: 2) }
|
4
4
|
|
5
|
-
subject { Feature::
|
5
|
+
subject { Feature::MultipleSubjects.new(user: user, widget: widget) }
|
6
6
|
|
7
7
|
its(:enabled?) { is_expected.to eq true }
|
8
8
|
its(:subjects) { is_expected.to eq user: user, widget: widget }
|
9
9
|
its("permissions.subjects") { is_expected.to eq [:user, :widget] }
|
10
|
-
|
11
|
-
describe "#enabled_for?" do
|
12
|
-
specify do
|
13
|
-
expect(Feature::Test.enabled_for?(user: double(id: 1, logged_in?: true),
|
14
|
-
widget: double(id: 2))).to eq true
|
15
|
-
expect(Feature::Test.enabled_for?(user: double(id: 1, logged_in?: false),
|
16
|
-
widget: double(id: 2))).to eq false
|
17
|
-
end
|
18
|
-
|
19
|
-
specify "invalid permissions" do
|
20
|
-
expect { Feature::Test.enabled_for?(widget: double) }.
|
21
|
-
to raise_error Feature::Subject::Invalid,
|
22
|
-
"Invalid or missing subjects for permissions: [:user]"
|
23
|
-
end
|
24
|
-
|
25
|
-
specify "collection" do
|
26
|
-
expect(Feature::Collection.enabled_for?(user: double(id: 1))).to eq true
|
27
|
-
expect(Feature::Collection.enabled_for?(user: double(id: 5))).to eq true
|
28
|
-
expect(Feature::Collection.enabled_for?(user: double(id: 10))).to eq true
|
29
|
-
expect(Feature::Collection.enabled_for?(user: double(id: 49))).to eq false
|
30
|
-
expect(Feature::Collection.enabled_for?(user: double(id: 51))).to eq true
|
31
|
-
end
|
32
|
-
end
|
33
10
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe Feature::
|
1
|
+
describe Feature::Operation::Or do
|
2
2
|
specify do
|
3
3
|
expect(described_class.call(double(id: 16), :id, {"in" => (10..20), "not" => 15})).to eq true
|
4
4
|
expect(described_class.call(double(id: 15), :id, {"in" => (10..20), "not" => 15})).to eq true
|
data/toggles.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toggles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Tribone
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -119,33 +119,37 @@ files:
|
|
119
119
|
- Gemfile
|
120
120
|
- Rakefile
|
121
121
|
- features/collection.yml
|
122
|
+
- features/multiple_subjects.yml
|
122
123
|
- features/nested_attributes.yml
|
123
|
-
- features/
|
124
|
+
- features/type.yml
|
124
125
|
- lib/toggles.rb
|
125
126
|
- lib/toggles/feature.rb
|
126
127
|
- lib/toggles/feature/base.rb
|
128
|
+
- lib/toggles/feature/operation.rb
|
129
|
+
- lib/toggles/feature/operation/and.rb
|
130
|
+
- lib/toggles/feature/operation/attribute.rb
|
131
|
+
- lib/toggles/feature/operation/gt.rb
|
132
|
+
- lib/toggles/feature/operation/in.rb
|
133
|
+
- lib/toggles/feature/operation/lt.rb
|
134
|
+
- lib/toggles/feature/operation/not.rb
|
135
|
+
- lib/toggles/feature/operation/or.rb
|
136
|
+
- lib/toggles/feature/operation/range.rb
|
127
137
|
- lib/toggles/feature/permissions.rb
|
128
|
-
- lib/toggles/feature/permissions/operation.rb
|
129
|
-
- lib/toggles/feature/permissions/operation/and.rb
|
130
|
-
- lib/toggles/feature/permissions/operation/attribute.rb
|
131
|
-
- lib/toggles/feature/permissions/operation/gt.rb
|
132
|
-
- lib/toggles/feature/permissions/operation/in.rb
|
133
|
-
- lib/toggles/feature/permissions/operation/lt.rb
|
134
|
-
- lib/toggles/feature/permissions/operation/not.rb
|
135
|
-
- lib/toggles/feature/permissions/operation/or.rb
|
136
|
-
- lib/toggles/feature/permissions/operation/range.rb
|
137
138
|
- lib/toggles/feature/subject.rb
|
138
139
|
- spec/spec_helper.rb
|
140
|
+
- spec/toggles/feature/acceptance/collection_spec.rb
|
141
|
+
- spec/toggles/feature/acceptance/multiple_subjects_spec.rb
|
142
|
+
- spec/toggles/feature/acceptance/nested_attributes_spec.rb
|
143
|
+
- spec/toggles/feature/acceptance/type_spec.rb
|
139
144
|
- spec/toggles/feature/base_spec.rb
|
140
|
-
- spec/toggles/feature/
|
141
|
-
- spec/toggles/feature/
|
142
|
-
- spec/toggles/feature/
|
143
|
-
- spec/toggles/feature/
|
144
|
-
- spec/toggles/feature/
|
145
|
-
- spec/toggles/feature/
|
146
|
-
- spec/toggles/feature/
|
147
|
-
- spec/toggles/feature/
|
148
|
-
- spec/toggles/feature/permissions/operation/range_spec.rb
|
145
|
+
- spec/toggles/feature/operation/and_spec.rb
|
146
|
+
- spec/toggles/feature/operation/attribute_spec.rb
|
147
|
+
- spec/toggles/feature/operation/gt_spec.rb
|
148
|
+
- spec/toggles/feature/operation/in_spec.rb
|
149
|
+
- spec/toggles/feature/operation/lt_spec.rb
|
150
|
+
- spec/toggles/feature/operation/not_spec.rb
|
151
|
+
- spec/toggles/feature/operation/or_spec.rb
|
152
|
+
- spec/toggles/feature/operation/range_spec.rb
|
149
153
|
- spec/toggles/feature/permissions_spec.rb
|
150
154
|
- spec/toggles/feature/subject_spec.rb
|
151
155
|
- toggles.gemspec
|
@@ -175,15 +179,18 @@ specification_version: 4
|
|
175
179
|
summary: YAML backed feature toggles
|
176
180
|
test_files:
|
177
181
|
- spec/spec_helper.rb
|
182
|
+
- spec/toggles/feature/acceptance/collection_spec.rb
|
183
|
+
- spec/toggles/feature/acceptance/multiple_subjects_spec.rb
|
184
|
+
- spec/toggles/feature/acceptance/nested_attributes_spec.rb
|
185
|
+
- spec/toggles/feature/acceptance/type_spec.rb
|
178
186
|
- spec/toggles/feature/base_spec.rb
|
179
|
-
- spec/toggles/feature/
|
180
|
-
- spec/toggles/feature/
|
181
|
-
- spec/toggles/feature/
|
182
|
-
- spec/toggles/feature/
|
183
|
-
- spec/toggles/feature/
|
184
|
-
- spec/toggles/feature/
|
185
|
-
- spec/toggles/feature/
|
186
|
-
- spec/toggles/feature/
|
187
|
-
- spec/toggles/feature/permissions/operation/range_spec.rb
|
187
|
+
- spec/toggles/feature/operation/and_spec.rb
|
188
|
+
- spec/toggles/feature/operation/attribute_spec.rb
|
189
|
+
- spec/toggles/feature/operation/gt_spec.rb
|
190
|
+
- spec/toggles/feature/operation/in_spec.rb
|
191
|
+
- spec/toggles/feature/operation/lt_spec.rb
|
192
|
+
- spec/toggles/feature/operation/not_spec.rb
|
193
|
+
- spec/toggles/feature/operation/or_spec.rb
|
194
|
+
- spec/toggles/feature/operation/range_spec.rb
|
188
195
|
- spec/toggles/feature/permissions_spec.rb
|
189
196
|
- spec/toggles/feature/subject_spec.rb
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require "toggles/feature/permissions/operation/and"
|
2
|
-
require "toggles/feature/permissions/operation/attribute"
|
3
|
-
require "toggles/feature/permissions/operation/gt"
|
4
|
-
require "toggles/feature/permissions/operation/in"
|
5
|
-
require "toggles/feature/permissions/operation/lt"
|
6
|
-
require "toggles/feature/permissions/operation/not"
|
7
|
-
require "toggles/feature/permissions/operation/or"
|
8
|
-
require "toggles/feature/permissions/operation/range"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Feature
|
2
|
-
class Permissions
|
3
|
-
module Operation
|
4
|
-
class Attribute
|
5
|
-
def self.call(entity, attr_name, expected)
|
6
|
-
if expected.kind_of? Hash
|
7
|
-
expected.all? do |operation, rules|
|
8
|
-
if OPERATIONS.include? operation.to_sym
|
9
|
-
OPERATIONS[operation.to_sym].call(entity, attr_name, rules)
|
10
|
-
else
|
11
|
-
Operation::Attribute.call(entity.send(attr_name), operation, rules)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
else
|
15
|
-
entity.send(attr_name) == expected
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Feature
|
2
|
-
class Permissions
|
3
|
-
module Operation
|
4
|
-
class In
|
5
|
-
def self.call(entity, attr_name, expected)
|
6
|
-
if expected.kind_of? Hash
|
7
|
-
expected = expected.reduce([]) do |list, (operation, args)|
|
8
|
-
OPERATIONS[operation.to_sym].call(args)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
expected.include? entity.send(attr_name.to_sym)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Feature
|
2
|
-
class Permissions
|
3
|
-
module Operation
|
4
|
-
class Not
|
5
|
-
def self.call(entity, attr_name, expected)
|
6
|
-
if expected.kind_of? Hash
|
7
|
-
expected.none? do |operation, value|
|
8
|
-
OPERATIONS[operation.to_sym].call(entity, attr_name, value)
|
9
|
-
end
|
10
|
-
else
|
11
|
-
entity.send(attr_name) != expected
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
describe "nested_attributes.yml" do
|
2
|
-
specify do
|
3
|
-
expect(
|
4
|
-
Feature::NestedAttributes.enabled_for?(
|
5
|
-
foo: double(bar: :two, baz: double(id: 51))
|
6
|
-
)
|
7
|
-
).to eq true
|
8
|
-
expect(
|
9
|
-
Feature::NestedAttributes.enabled_for?(
|
10
|
-
foo: double(bar: :two, baz: double(id: 10))
|
11
|
-
)
|
12
|
-
).to eq true
|
13
|
-
|
14
|
-
expect(
|
15
|
-
Feature::NestedAttributes.enabled_for?(
|
16
|
-
foo: double(bar: :one, baz: double(id: 51))
|
17
|
-
)
|
18
|
-
).to eq false
|
19
|
-
expect(
|
20
|
-
Feature::NestedAttributes.enabled_for?(
|
21
|
-
foo: double(bar: :two, baz: double(id: 50))
|
22
|
-
)
|
23
|
-
).to eq false
|
24
|
-
end
|
25
|
-
end
|