concealer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  Gemfile.lock
2
+ pkg/*
data/README.rdoc CHANGED
@@ -46,12 +46,14 @@ The default strategy for Concealer is Concealer::Strategy::Allow which forwards
46
46
  * Concealer::Strategy::Deny
47
47
  * Concealer::Strategy::Whitelist
48
48
  * Concealer::Strategy::Blacklist
49
+ * Concealer::Strategy::All
50
+ * Concealer::Strategy::Any
49
51
 
50
52
  You can set the strategy for Concealer using <tt>Concealer.strategy=</tt>
51
53
 
52
54
  Concealer.strategy = Concealer::Strategy::Deny.new
53
55
 
54
- user = User.new
56
+ user = User.new(:name => 'Frank', :email => 'frank@example.com')
55
57
  user.concealed.name # => nil
56
58
  user.concealed.email # => nil
57
59
 
@@ -5,6 +5,8 @@ module Concealer
5
5
  autoload :Deny, 'concealer/strategy/deny'
6
6
  autoload :Blacklist, 'concealer/strategy/blacklist'
7
7
  autoload :Whitelist, 'concealer/strategy/whitelist'
8
+ autoload :Any, 'concealer/strategy/any'
9
+ autoload :All, 'concealer/strategy/all'
8
10
  autoload :MultiLevel, 'concealer/strategy/multi_level'
9
11
 
10
12
  def allow?(model, method, args)
@@ -0,0 +1,9 @@
1
+ class Concealer::Strategy::All < Concealer::Strategy
2
+ def initialize(*strategies)
3
+ @strategies = strategies.flatten
4
+ end
5
+
6
+ def allow?(model, method, args)
7
+ @strategies.all? { |s| s.allow?(model, method, args) }
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Concealer::Strategy::Any < Concealer::Strategy
2
+ def initialize(*strategies)
3
+ @strategies = strategies.flatten
4
+ end
5
+
6
+ def allow?(model, method, args)
7
+ @strategies.any? { |s| s.allow?(model, method, args) }
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Concealer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Concealer::Strategy::All do
4
+
5
+ let(:strategy_1) { mock(Concealer::Strategy::Allow.new) }
6
+ let(:strategy_2) { mock(Concealer::Strategy::Allow.new) }
7
+
8
+ subject { Concealer::Strategy::All.new(strategy_1, strategy_2) }
9
+
10
+ context 'both deny' do
11
+ before(:each) do
12
+ strategy_1.stub!(:allow?).and_return(false)
13
+ strategy_2.stub!(:allow?).and_return(false)
14
+ end
15
+
16
+ it "should deny the call" do
17
+ subject.allow?(nil, nil, nil).should be_false
18
+ end
19
+ end
20
+
21
+ context 'both allow' do
22
+ before(:each) do
23
+ strategy_1.stub!(:allow?).and_return(true)
24
+ strategy_2.stub!(:allow?).and_return(true)
25
+ end
26
+
27
+ it "should allow the call" do
28
+ subject.allow?(nil, nil, nil).should be_true
29
+ end
30
+ end
31
+
32
+ context 'only one allows' do
33
+ before(:each) do
34
+ strategy_1.stub!(:allow?).and_return(true)
35
+ strategy_2.stub!(:allow?).and_return(false)
36
+ end
37
+
38
+ it "should deny the call" do
39
+ subject.allow?(nil, nil, nil).should be_false
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Concealer::Strategy::Any do
4
+
5
+ let(:strategy_1) { mock(Concealer::Strategy::Allow.new) }
6
+ let(:strategy_2) { mock(Concealer::Strategy::Allow.new) }
7
+
8
+ subject { Concealer::Strategy::Any.new(strategy_1, strategy_2) }
9
+
10
+ context 'both deny' do
11
+ before(:each) do
12
+ strategy_1.stub!(:allow?).and_return(false)
13
+ strategy_2.stub!(:allow?).and_return(false)
14
+ end
15
+
16
+ it "should deny the call" do
17
+ subject.allow?(nil, nil, nil).should be_false
18
+ end
19
+ end
20
+
21
+ context 'both allow' do
22
+ before(:each) do
23
+ strategy_1.stub!(:allow?).and_return(true)
24
+ strategy_2.stub!(:allow?).and_return(true)
25
+ end
26
+
27
+ it "should allow the call" do
28
+ subject.allow?(nil, nil, nil).should be_true
29
+ end
30
+ end
31
+
32
+ context 'only one allows' do
33
+ before(:each) do
34
+ strategy_1.stub!(:allow?).and_return(true)
35
+ strategy_2.stub!(:allow?).and_return(false)
36
+ end
37
+
38
+ it "should allow the call" do
39
+ subject.allow?(nil, nil, nil).should be_true
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concealer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benedikt Deicke
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-28 00:00:00 +01:00
19
+ date: 2011-03-08 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -88,7 +88,9 @@ files:
88
88
  - lib/concealer/fallback/string.rb
89
89
  - lib/concealer/proxy.rb
90
90
  - lib/concealer/strategy.rb
91
+ - lib/concealer/strategy/all.rb
91
92
  - lib/concealer/strategy/allow.rb
93
+ - lib/concealer/strategy/any.rb
92
94
  - lib/concealer/strategy/blacklist.rb
93
95
  - lib/concealer/strategy/deny.rb
94
96
  - lib/concealer/strategy/multi_level.rb
@@ -99,7 +101,9 @@ files:
99
101
  - spec/concealer/fallback/string_spec.rb
100
102
  - spec/concealer/fallback_spec.rb
101
103
  - spec/concealer/proxy_spec.rb
104
+ - spec/concealer/strategy/all_spec.rb
102
105
  - spec/concealer/strategy/allow_spec.rb
106
+ - spec/concealer/strategy/any_spec.rb
103
107
  - spec/concealer/strategy/blacklist_spec.rb
104
108
  - spec/concealer/strategy/deny_spec.rb
105
109
  - spec/concealer/strategy/multi_level_spec.rb
@@ -150,7 +154,9 @@ test_files:
150
154
  - spec/concealer/fallback/string_spec.rb
151
155
  - spec/concealer/fallback_spec.rb
152
156
  - spec/concealer/proxy_spec.rb
157
+ - spec/concealer/strategy/all_spec.rb
153
158
  - spec/concealer/strategy/allow_spec.rb
159
+ - spec/concealer/strategy/any_spec.rb
154
160
  - spec/concealer/strategy/blacklist_spec.rb
155
161
  - spec/concealer/strategy/deny_spec.rb
156
162
  - spec/concealer/strategy/multi_level_spec.rb