toggles 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51bb6e97c911c1565aeb75d196617d10e71d9903
4
- data.tar.gz: dd23e2efe0e2d7973efecc74692e2c87630c799a
3
+ metadata.gz: 667d45b0572c3986b8f26a65f9d875c29418fb5f
4
+ data.tar.gz: dcf2a50e338291a73cb2ce901a1eed0d5b12cdec
5
5
  SHA512:
6
- metadata.gz: 2020f4c3044bec0802bc2dc168f1fa2e7f5053e5b90185272cbcf57e968453c4b49968ec948867505bf10b2d8ad75944cc2e78fbe8cac52d47d9e05648488294
7
- data.tar.gz: abe63515e325397441f189c63e4261e23769127ed1a8d2994af7b9d0cd34323854edf989e2aad44de28b538da2a0747ba7a01fb996b4c3ef80a4fbcbaaf17e90
6
+ metadata.gz: 6b40d286dd30e05530d36cab7fde5cb9a1ac78fafb152130bd58428f0648099b44567d8b8b3ab23bcb2122142d819d5c08e251a3135c7d9e74671b217725ec5e
7
+ data.tar.gz: 7d8fb44ef3432bafbfe5a7e47eb75e59c7498f210bbca9ff092164654aba4e07dbce2aa411b1adc742c035c0022a5a8538e79b8751bf1eae02146b9cc2d00e7d
@@ -0,0 +1,12 @@
1
+ foo:
2
+ bar:
3
+ not:
4
+ in:
5
+ - :one
6
+ - two
7
+ baz:
8
+ id:
9
+ or:
10
+ gt: 50
11
+ in:
12
+ - 10
@@ -4,8 +4,12 @@ module Feature
4
4
  class Attribute
5
5
  def self.call(entity, attr_name, expected)
6
6
  if expected.kind_of? Hash
7
- expected.all? do |operation, value|
8
- OPERATIONS[operation.to_sym].call(entity, attr_name, value)
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
9
13
  end
10
14
  else
11
15
  entity.send(attr_name) == expected
@@ -4,16 +4,12 @@ module Feature
4
4
  class Permissions
5
5
  extend Forwardable
6
6
 
7
- attr_reader :path
7
+ attr_reader :rules
8
8
 
9
9
  def_delegators :rules, :all?, :keys
10
10
 
11
11
  def initialize(path)
12
- @path = path
13
- end
14
-
15
- def rules
16
- @rules ||= YAML.load(File.read(path))
12
+ @rules = YAML.load(File.read(path))
17
13
  end
18
14
 
19
15
  def subjects
@@ -2,7 +2,7 @@ module Feature
2
2
  module Subject
3
3
  class Invalid < StandardError
4
4
  def initialize(args)
5
- super("Invalid subjects for permissions: #{args}")
5
+ super("Invalid or missing subjects for permissions: #{args}")
6
6
  end
7
7
  end
8
8
 
@@ -18,7 +18,8 @@ describe Feature::Base do
18
18
 
19
19
  specify "invalid permissions" do
20
20
  expect { Feature::Test.enabled_for?(widget: double) }.
21
- to raise_error Feature::Subject::Invalid, "Invalid subjects for permissions: [:user]"
21
+ to raise_error Feature::Subject::Invalid,
22
+ "Invalid or missing subjects for permissions: [:user]"
22
23
  end
23
24
 
24
25
  specify "collection" do
@@ -0,0 +1,25 @@
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
@@ -3,7 +3,6 @@ describe Feature::Permissions do
3
3
 
4
4
  subject { Feature::Permissions.new(path) }
5
5
 
6
- its(:path) { is_expected.to eq path }
7
6
  its(:rules) { is_expected.to eq({"user"=>{"id"=>1, "logged_in?"=>true},
8
7
  "widget"=>{"id"=>2}}) }
9
8
  its(:subjects) { [:user, :widget] }
@@ -18,7 +17,8 @@ describe Feature::Permissions do
18
17
 
19
18
  specify "invalid subjects" do
20
19
  expect { subject.valid_for?(user: double) }.
21
- to raise_error Feature::Subject::Invalid, "Invalid subjects for permissions: [:widget]"
20
+ to raise_error Feature::Subject::Invalid,
21
+ "Invalid or missing subjects for permissions: [:widget]"
22
22
  end
23
23
  end
24
24
  end
@@ -2,7 +2,7 @@ describe Feature::Subject do
2
2
  describe Feature::Subject::Invalid do
3
3
  subject { Feature::Subject::Invalid.new([:user]) }
4
4
 
5
- its(:message) { is_expected.to eq "Invalid subjects for permissions: [:user]" }
5
+ its(:message) { is_expected.to eq "Invalid or missing subjects for permissions: [:user]" }
6
6
  end
7
7
 
8
8
  describe "#difference" do
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.4"
3
+ s.version = "0.0.5"
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.4
4
+ version: 0.0.5
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-10 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - Gemfile
120
120
  - Rakefile
121
121
  - features/collection.yml
122
+ - features/nested_attributes.yml
122
123
  - features/test.yml
123
124
  - lib/toggles.rb
124
125
  - lib/toggles/feature.rb
@@ -136,6 +137,7 @@ files:
136
137
  - lib/toggles/feature/subject.rb
137
138
  - spec/spec_helper.rb
138
139
  - spec/toggles/feature/base_spec.rb
140
+ - spec/toggles/feature/nested_attributes_spec.rb
139
141
  - spec/toggles/feature/permissions/operation/and_spec.rb
140
142
  - spec/toggles/feature/permissions/operation/attribute_spec.rb
141
143
  - spec/toggles/feature/permissions/operation/gt_spec.rb
@@ -146,7 +148,6 @@ files:
146
148
  - spec/toggles/feature/permissions/operation/range_spec.rb
147
149
  - spec/toggles/feature/permissions_spec.rb
148
150
  - spec/toggles/feature/subject_spec.rb
149
- - spec/toggles_spec.rb
150
151
  - toggles.gemspec
151
152
  homepage: ''
152
153
  licenses:
@@ -175,6 +176,7 @@ summary: YAML backed feature toggles
175
176
  test_files:
176
177
  - spec/spec_helper.rb
177
178
  - spec/toggles/feature/base_spec.rb
179
+ - spec/toggles/feature/nested_attributes_spec.rb
178
180
  - spec/toggles/feature/permissions/operation/and_spec.rb
179
181
  - spec/toggles/feature/permissions/operation/attribute_spec.rb
180
182
  - spec/toggles/feature/permissions/operation/gt_spec.rb
@@ -185,4 +187,3 @@ test_files:
185
187
  - spec/toggles/feature/permissions/operation/range_spec.rb
186
188
  - spec/toggles/feature/permissions_spec.rb
187
189
  - spec/toggles/feature/subject_spec.rb
188
- - spec/toggles_spec.rb
data/spec/toggles_spec.rb DELETED
File without changes