toggles 0.0.3 → 0.0.4

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: a4ae066034b92038bdbffd7082fdaefb09108ecb
4
- data.tar.gz: 3296e6281f6ab89e6e3e75454ebfca6ec72f2d1d
3
+ metadata.gz: 51bb6e97c911c1565aeb75d196617d10e71d9903
4
+ data.tar.gz: dd23e2efe0e2d7973efecc74692e2c87630c799a
5
5
  SHA512:
6
- metadata.gz: a1eefd9031d02acf595957bc6f7fd3254d3dd31d7f1c840490b645d425d4d01d407bb02d0b73f6f55c29dcdfde7d9440d29d7e5a7ae06615e28e836a7563fe92
7
- data.tar.gz: eba16fc60170e6b3a43d8422d5ac8b93911a68f466cbed5469ee9315c7f05ba0cf0a6cb75a9103b32d40ecdd5c2908b3a70d0b1f57deccb054a87eeed8e82fc2
6
+ metadata.gz: 2020f4c3044bec0802bc2dc168f1fa2e7f5053e5b90185272cbcf57e968453c4b49968ec948867505bf10b2d8ad75944cc2e78fbe8cac52d47d9e05648488294
7
+ data.tar.gz: abe63515e325397441f189c63e4261e23769127ed1a8d2994af7b9d0cd34323854edf989e2aad44de28b538da2a0747ba7a01fb996b4c3ef80a4fbcbaaf17e90
@@ -10,6 +10,7 @@ module Feature
10
10
  gt: Permissions::Operation::GreaterThan,
11
11
  in: Permissions::Operation::In,
12
12
  lt: Permissions::Operation::LessThan,
13
+ not: Permissions::Operation::Not,
13
14
  or: Permissions::Operation::Or,
14
15
  range: Permissions::Operation::Range}
15
16
  end
@@ -1,7 +1,8 @@
1
1
  require "toggles/feature/permissions/operation/and"
2
+ require "toggles/feature/permissions/operation/attribute"
2
3
  require "toggles/feature/permissions/operation/gt"
3
4
  require "toggles/feature/permissions/operation/in"
4
5
  require "toggles/feature/permissions/operation/lt"
6
+ require "toggles/feature/permissions/operation/not"
5
7
  require "toggles/feature/permissions/operation/or"
6
- require "toggles/feature/permissions/operation/property"
7
8
  require "toggles/feature/permissions/operation/range"
@@ -4,9 +4,7 @@ module Feature
4
4
  class And
5
5
  def self.call(entity, attr_name, expected)
6
6
  expected.all? do |operation, value|
7
- OPERATIONS.fetch(operation.to_sym, Attribute).call(
8
- entity, attr_name, value
9
- )
7
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
10
8
  end
11
9
  end
12
10
  end
@@ -5,9 +5,7 @@ module Feature
5
5
  def self.call(entity, attr_name, expected)
6
6
  if expected.kind_of? Hash
7
7
  expected.all? do |operation, value|
8
- OPERATIONS.fetch(operation.to_sym, Operation::Attribute).call(
9
- entity, attr_name, value
10
- )
8
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
11
9
  end
12
10
  else
13
11
  entity.send(attr_name) == expected
@@ -0,0 +1,17 @@
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
@@ -4,9 +4,7 @@ module Feature
4
4
  class Or
5
5
  def self.call(entity, attr_name, expected)
6
6
  expected.any? do |operation, value|
7
- OPERATIONS.fetch(operation.to_sym, Attribute).call(
8
- entity, attr_name, value
9
- )
7
+ OPERATIONS[operation.to_sym].call(entity, attr_name, value)
10
8
  end
11
9
  end
12
10
  end
@@ -0,0 +1,9 @@
1
+ describe Feature::Permissions::Operation::And do
2
+ specify do
3
+ [[60, true], [40, false], [80, false]].each do |(id, expected)|
4
+ expect(
5
+ described_class.call(double(id: id), :id, {"gt" => 50, "lt" => 70})
6
+ ).to eq expected
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ describe Feature::Permissions::Operation::Attribute do
2
+ specify do
3
+ expect(described_class.call(double(id: 50), :id, 50)).to eq true
4
+ expect(described_class.call(double(id: 50), :id, 51)).to eq false
5
+
6
+ expect(described_class.call(double(id: 50), :id, {"in" => (0..50), "not" => 49})).to eq true
7
+ expect(described_class.call(double(id: 49), :id, {"in" => (0..50), "not" => 49})).to eq false
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ describe Feature::Permissions::Operation::GreaterThan do
2
+ specify do
3
+ expect(described_class.call(double(id: 50), :id, 40)).to eq true
4
+ expect(described_class.call(double(id: 50), :id, 60)).to eq false
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ describe Feature::Permissions::Operation::In do
2
+ specify do
3
+ expect(described_class.call(double(id: 50), :id, {"range" => [40, 60]})).to eq true
4
+ expect(described_class.call(double(id: 50), :id, [1])).to eq false
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ describe Feature::Permissions::Operation::LessThan do
2
+ specify do
3
+ expect(described_class.call(double(id: 50), :id, 60)).to eq true
4
+ expect(described_class.call(double(id: 50), :id, 40)).to eq false
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ describe Feature::Permissions::Operation::Not do
2
+ specify do
3
+ expect(described_class.call(double(id: 50), :id, {"in" => (10..20)})).to eq true
4
+ expect(described_class.call(double(id: 50), :id, 50)).to eq false
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ describe Feature::Permissions::Operation::Or do
2
+ specify do
3
+ expect(described_class.call(double(id: 16), :id, {"in" => (10..20), "not" => 15})).to eq true
4
+ expect(described_class.call(double(id: 15), :id, {"in" => (10..20), "not" => 15})).to eq true
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ describe Feature::Permissions::Operation::Range do
2
+ specify do
3
+ expect(described_class.call([10, 20])).to eq (10..20)
4
+ end
5
+ end
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.3"
3
+ s.version = "0.0.4"
4
4
  s.authors = ["Andrew Tribone"]
5
5
  s.summary = "YAML backed feature toggles"
6
6
  s.email = "tribone@easypost.com"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toggles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Tribone
@@ -126,15 +126,24 @@ files:
126
126
  - lib/toggles/feature/permissions.rb
127
127
  - lib/toggles/feature/permissions/operation.rb
128
128
  - lib/toggles/feature/permissions/operation/and.rb
129
+ - lib/toggles/feature/permissions/operation/attribute.rb
129
130
  - lib/toggles/feature/permissions/operation/gt.rb
130
131
  - lib/toggles/feature/permissions/operation/in.rb
131
132
  - lib/toggles/feature/permissions/operation/lt.rb
133
+ - lib/toggles/feature/permissions/operation/not.rb
132
134
  - lib/toggles/feature/permissions/operation/or.rb
133
- - lib/toggles/feature/permissions/operation/property.rb
134
135
  - lib/toggles/feature/permissions/operation/range.rb
135
136
  - lib/toggles/feature/subject.rb
136
137
  - spec/spec_helper.rb
137
138
  - spec/toggles/feature/base_spec.rb
139
+ - spec/toggles/feature/permissions/operation/and_spec.rb
140
+ - spec/toggles/feature/permissions/operation/attribute_spec.rb
141
+ - spec/toggles/feature/permissions/operation/gt_spec.rb
142
+ - spec/toggles/feature/permissions/operation/in_spec.rb
143
+ - spec/toggles/feature/permissions/operation/lt_spec.rb
144
+ - spec/toggles/feature/permissions/operation/not_spec.rb
145
+ - spec/toggles/feature/permissions/operation/or_spec.rb
146
+ - spec/toggles/feature/permissions/operation/range_spec.rb
138
147
  - spec/toggles/feature/permissions_spec.rb
139
148
  - spec/toggles/feature/subject_spec.rb
140
149
  - spec/toggles_spec.rb
@@ -166,6 +175,14 @@ summary: YAML backed feature toggles
166
175
  test_files:
167
176
  - spec/spec_helper.rb
168
177
  - spec/toggles/feature/base_spec.rb
178
+ - spec/toggles/feature/permissions/operation/and_spec.rb
179
+ - spec/toggles/feature/permissions/operation/attribute_spec.rb
180
+ - spec/toggles/feature/permissions/operation/gt_spec.rb
181
+ - spec/toggles/feature/permissions/operation/in_spec.rb
182
+ - spec/toggles/feature/permissions/operation/lt_spec.rb
183
+ - spec/toggles/feature/permissions/operation/not_spec.rb
184
+ - spec/toggles/feature/permissions/operation/or_spec.rb
185
+ - spec/toggles/feature/permissions/operation/range_spec.rb
169
186
  - spec/toggles/feature/permissions_spec.rb
170
187
  - spec/toggles/feature/subject_spec.rb
171
188
  - spec/toggles_spec.rb