toggles 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/features/{test.yml → multiple_subjects.yml} +0 -0
  3. data/features/type.yml +6 -0
  4. data/lib/toggles/feature.rb +8 -8
  5. data/lib/toggles/feature/operation.rb +8 -0
  6. data/lib/toggles/feature/operation/and.rb +11 -0
  7. data/lib/toggles/feature/operation/attribute.rb +19 -0
  8. data/lib/toggles/feature/operation/gt.rb +9 -0
  9. data/lib/toggles/feature/operation/in.rb +15 -0
  10. data/lib/toggles/feature/operation/lt.rb +9 -0
  11. data/lib/toggles/feature/operation/not.rb +15 -0
  12. data/lib/toggles/feature/operation/or.rb +11 -0
  13. data/lib/toggles/feature/operation/range.rb +10 -0
  14. data/lib/toggles/feature/permissions.rb +9 -4
  15. data/spec/toggles/feature/acceptance/collection_spec.rb +9 -0
  16. data/spec/toggles/feature/acceptance/multiple_subjects_spec.rb +17 -0
  17. data/spec/toggles/feature/acceptance/nested_attributes_spec.rb +13 -0
  18. data/spec/toggles/feature/acceptance/type_spec.rb +6 -0
  19. data/spec/toggles/feature/base_spec.rb +1 -24
  20. data/spec/toggles/feature/{permissions/operation → operation}/and_spec.rb +1 -1
  21. data/spec/toggles/feature/{permissions/operation → operation}/attribute_spec.rb +1 -1
  22. data/spec/toggles/feature/{permissions/operation → operation}/gt_spec.rb +1 -1
  23. data/spec/toggles/feature/{permissions/operation → operation}/in_spec.rb +1 -1
  24. data/spec/toggles/feature/{permissions/operation → operation}/lt_spec.rb +1 -1
  25. data/spec/toggles/feature/{permissions/operation → operation}/not_spec.rb +1 -1
  26. data/spec/toggles/feature/{permissions/operation → operation}/or_spec.rb +1 -1
  27. data/spec/toggles/feature/{permissions/operation → operation}/range_spec.rb +1 -1
  28. data/spec/toggles/feature/permissions_spec.rb +1 -1
  29. data/toggles.gemspec +1 -1
  30. metadata +37 -30
  31. data/lib/toggles/feature/permissions/operation.rb +0 -8
  32. data/lib/toggles/feature/permissions/operation/and.rb +0 -13
  33. data/lib/toggles/feature/permissions/operation/attribute.rb +0 -21
  34. data/lib/toggles/feature/permissions/operation/gt.rb +0 -11
  35. data/lib/toggles/feature/permissions/operation/in.rb +0 -17
  36. data/lib/toggles/feature/permissions/operation/lt.rb +0 -11
  37. data/lib/toggles/feature/permissions/operation/not.rb +0 -17
  38. data/lib/toggles/feature/permissions/operation/or.rb +0 -13
  39. data/lib/toggles/feature/permissions/operation/range.rb +0 -12
  40. 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: 667d45b0572c3986b8f26a65f9d875c29418fb5f
4
- data.tar.gz: dcf2a50e338291a73cb2ce901a1eed0d5b12cdec
3
+ metadata.gz: 31164f56157983183da56700b347bb70a5373058
4
+ data.tar.gz: 9b258b42d5b7e8d7fdf95b91ec8c19ddfab5820f
5
5
  SHA512:
6
- metadata.gz: 6b40d286dd30e05530d36cab7fde5cb9a1ac78fafb152130bd58428f0648099b44567d8b8b3ab23bcb2122142d819d5c08e251a3135c7d9e74671b217725ec5e
7
- data.tar.gz: 7d8fb44ef3432bafbfe5a7e47eb75e59c7498f210bbca9ff092164654aba4e07dbce2aa411b1adc742c035c0022a5a8538e79b8751bf1eae02146b9cc2d00e7d
6
+ metadata.gz: 2f70ab0bda18fe55346c769b49eafcb1d67a7faf0e73eefbcf86686d8131fdc951ece6caf64f71722ab454211780b0525ab2fe6c2a6fdd781fe1ad87432adcae
7
+ data.tar.gz: fda41fa20f04da055008917544349718ca39b24ab6455e644651558f05cbcb5e50e5d85d2af73e8c2e47f33fd3881603e5776e0d6cfda4f979e6cb6f4f39d820
File without changes
data/features/type.yml ADDED
@@ -0,0 +1,6 @@
1
+ user_id:
2
+ not:
3
+ in:
4
+ range:
5
+ - 20
6
+ - 30
@@ -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: Permissions::Operation::And,
10
- gt: Permissions::Operation::GreaterThan,
11
- in: Permissions::Operation::In,
12
- lt: Permissions::Operation::LessThan,
13
- not: Permissions::Operation::Not,
14
- or: Permissions::Operation::Or,
15
- range: Permissions::Operation::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,11 @@
1
+ module Feature
2
+ module Operation
3
+ class And
4
+ def self.call(entity, attr_name, expected)
5
+ expected.all? do |operation, value|
6
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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,9 @@
1
+ module Feature
2
+ module Operation
3
+ class GreaterThan
4
+ def self.call(entity, attr_name, expected)
5
+ entity.send(attr_name) > expected
6
+ end
7
+ end
8
+ end
9
+ 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,9 @@
1
+ module Feature
2
+ module Operation
3
+ class LessThan
4
+ def self.call(entity, attr_name, expected)
5
+ entity.send(attr_name) < expected
6
+ end
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,11 @@
1
+ module Feature
2
+ module Operation
3
+ class Or
4
+ def self.call(entity, attr_name, expected)
5
+ expected.any? do |operation, value|
6
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Feature
2
+ module Operation
3
+ class Range
4
+ def self.call(args)
5
+ raise StandardError, "Invalid range operation" if args.size != 2
6
+ (args.first..args.last)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,4 @@
1
- require "toggles/feature/permissions/operation"
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
@@ -0,0 +1,6 @@
1
+ describe Feature::Type do
2
+ specify do
3
+ expect(Feature::Type.enabled_for?(user_id: 1)).to eq true
4
+ expect(Feature::Type.enabled_for?(user_id: 25)).to eq false
5
+ end
6
+ 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::Test.new(user: user, widget: widget) }
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::Permissions::Operation::And do
1
+ describe Feature::Operation::And do
2
2
  specify do
3
3
  [[60, true], [40, false], [80, false]].each do |(id, expected)|
4
4
  expect(
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::Attribute do
1
+ describe Feature::Operation::Attribute do
2
2
  specify do
3
3
  expect(described_class.call(double(id: 50), :id, 50)).to eq true
4
4
  expect(described_class.call(double(id: 50), :id, 51)).to eq false
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::GreaterThan do
1
+ describe Feature::Operation::GreaterThan do
2
2
  specify do
3
3
  expect(described_class.call(double(id: 50), :id, 40)).to eq true
4
4
  expect(described_class.call(double(id: 50), :id, 60)).to eq false
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::In do
1
+ describe Feature::Operation::In do
2
2
  specify do
3
3
  expect(described_class.call(double(id: 50), :id, {"range" => [40, 60]})).to eq true
4
4
  expect(described_class.call(double(id: 50), :id, [1])).to eq false
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::LessThan do
1
+ describe Feature::Operation::LessThan do
2
2
  specify do
3
3
  expect(described_class.call(double(id: 50), :id, 60)).to eq true
4
4
  expect(described_class.call(double(id: 50), :id, 40)).to eq false
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::Not do
1
+ describe Feature::Operation::Not do
2
2
  specify do
3
3
  expect(described_class.call(double(id: 50), :id, {"in" => (10..20)})).to eq true
4
4
  expect(described_class.call(double(id: 50), :id, 50)).to eq false
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::Or do
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
@@ -1,4 +1,4 @@
1
- describe Feature::Permissions::Operation::Range do
1
+ describe Feature::Operation::Range do
2
2
  specify do
3
3
  expect(described_class.call([10, 20])).to eq (10..20)
4
4
  end
@@ -1,5 +1,5 @@
1
1
  describe Feature::Permissions do
2
- let(:path) { "features/test.yml" }
2
+ let(:path) { "features/multiple_subjects.yml" }
3
3
 
4
4
  subject { Feature::Permissions.new(path) }
5
5
 
data/toggles.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "toggles"
3
- s.version = "0.0.5"
3
+ s.version = "0.0.6"
4
4
  s.authors = ["Andrew Tribone"]
5
5
  s.summary = "YAML backed feature toggles"
6
6
  s.email = "tribone@easypost.com"
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.5
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-17 00:00:00.000000000 Z
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/test.yml
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/nested_attributes_spec.rb
141
- - spec/toggles/feature/permissions/operation/and_spec.rb
142
- - spec/toggles/feature/permissions/operation/attribute_spec.rb
143
- - spec/toggles/feature/permissions/operation/gt_spec.rb
144
- - spec/toggles/feature/permissions/operation/in_spec.rb
145
- - spec/toggles/feature/permissions/operation/lt_spec.rb
146
- - spec/toggles/feature/permissions/operation/not_spec.rb
147
- - spec/toggles/feature/permissions/operation/or_spec.rb
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/nested_attributes_spec.rb
180
- - spec/toggles/feature/permissions/operation/and_spec.rb
181
- - spec/toggles/feature/permissions/operation/attribute_spec.rb
182
- - spec/toggles/feature/permissions/operation/gt_spec.rb
183
- - spec/toggles/feature/permissions/operation/in_spec.rb
184
- - spec/toggles/feature/permissions/operation/lt_spec.rb
185
- - spec/toggles/feature/permissions/operation/not_spec.rb
186
- - spec/toggles/feature/permissions/operation/or_spec.rb
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,13 +0,0 @@
1
- module Feature
2
- class Permissions
3
- module Operation
4
- class And
5
- def self.call(entity, attr_name, expected)
6
- expected.all? do |operation, value|
7
- OPERATIONS[operation.to_sym].call(entity, attr_name, value)
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -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,11 +0,0 @@
1
- module Feature
2
- class Permissions
3
- module Operation
4
- class GreaterThan
5
- def self.call(entity, attr_name, expected)
6
- entity.send(attr_name) > expected
7
- end
8
- end
9
- end
10
- end
11
- 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,11 +0,0 @@
1
- module Feature
2
- class Permissions
3
- module Operation
4
- class LessThan
5
- def self.call(entity, attr_name, expected)
6
- entity.send(attr_name) < expected
7
- end
8
- end
9
- end
10
- end
11
- 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,13 +0,0 @@
1
- module Feature
2
- class Permissions
3
- module Operation
4
- class Or
5
- def self.call(entity, attr_name, expected)
6
- expected.any? do |operation, value|
7
- OPERATIONS[operation.to_sym].call(entity, attr_name, value)
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- module Feature
2
- class Permissions
3
- module Operation
4
- class Range
5
- def self.call(args)
6
- raise StandardError, "Invalid range operation" if args.size != 2
7
- (args.first..args.last)
8
- end
9
- end
10
- end
11
- end
12
- 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