you_shall_not_pass 0.1.0 → 0.2.1

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: 2f7b94fd90514299c816fa9f4f55a4f50fe7fadb
4
- data.tar.gz: 2c20e0ded03fde67292cb5fbed5a11a7ffa959b3
3
+ metadata.gz: ff264efe0dc106fb920967bfa713da23337f8c2b
4
+ data.tar.gz: 53289da65c93a55c9e54e26eecf1073c8366f9c1
5
5
  SHA512:
6
- metadata.gz: e7e767bf6c234ab62c6ad73c94d8ce37e90fc25bdf5c2948d6126bc715351a3367164f1fe490ed28c9ccd17e884a86629077f6d81c530b884ccf205c6d6c03d8
7
- data.tar.gz: 8512dcc4f5df0b615619ebc360387d400a56ce7db016d1598defaedef9defe7902b1ccaff82a9f62f006e22182383929c3c9e0e01512a36d914ac73bfcdf7aac
6
+ metadata.gz: 88c5decdaf3f6accef1fbfab7311185cdd8f8b9b5a20228f9c80f503d580a8f1fe252faa30712723e488229ef50c1db68844c5667d9be5b4087bbb6c94b7f3cf
7
+ data.tar.gz: 4cc68aad2573c7360cb30c041c277405f509cc4abde5ff7814da8dcdd52cbf6def61475baecabd5bf3a7434dfe6a14ee1efb2e7e9aaf3bc268707d6f32e2aeef
@@ -31,10 +31,14 @@ module YouShallNotPass
31
31
  end
32
32
  end
33
33
 
34
- def perform_for(permission, **args)
34
+ def perform_if(permission, **args)
35
35
  yield if can?(permission, **args)
36
36
  end
37
37
 
38
+ def perform_unless(permission, **args)
39
+ yield unless can?(permission, **args)
40
+ end
41
+
38
42
  def policies
39
43
  @policies ||= __set_policies__
40
44
  end
@@ -58,7 +62,7 @@ module YouShallNotPass
58
62
  @__dsl_policies__ ||= {}
59
63
  end
60
64
 
61
- def self.authorize(name, &block)
65
+ def self.policy(name, &block)
62
66
  __dsl_policies__[name] = block
63
67
  end
64
68
 
@@ -1,3 +1,3 @@
1
1
  module YouShallNotPass
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -128,7 +128,7 @@ scope YouShallNotPass::Authorizator do
128
128
  end
129
129
  end
130
130
 
131
- scope "#perform_for" do
131
+ scope "performing" do
132
132
  class BasicAuthorizator < YouShallNotPass::Authorizator
133
133
  def policies
134
134
  {
@@ -140,30 +140,59 @@ scope YouShallNotPass::Authorizator do
140
140
  end
141
141
  end
142
142
 
143
- let(:authorizator) { BasicAuthorizator.new }
143
+ scope "#perform_if" do
144
+ let(:authorizator) { BasicAuthorizator.new }
144
145
 
145
- spec "executes the block if it is allowed" do
146
- authorizator.perform_for(:can) do
147
- @i_can = true
146
+ spec "executes the block if it is allowed" do
147
+ authorizator.perform_if(:can) do
148
+ @i_can = true
149
+ end
150
+
151
+ !! defined? @i_can
148
152
  end
149
153
 
150
- !! defined? @i_can
151
- end
154
+ spec "doesn't execute the block if it isn't allowed" do
155
+ authorizator.perform_if(:cant) do
156
+ @i_can = true
157
+ end
152
158
 
153
- spec "doesn't execute the block if it isn't allowed" do
154
- authorizator.perform_for(:cant) do
155
- @i_can = true
159
+ ! defined? @i_can
156
160
  end
157
161
 
158
- ! defined? @i_can
162
+ spec "passes the arguments" do
163
+ authorizator.perform_if(:use_args, a: :a, b: :b) do
164
+ @i_can = true
165
+ end
166
+
167
+ !! defined? @i_can
168
+ end
159
169
  end
160
170
 
161
- spec "passes the arguments" do
162
- authorizator.perform_for(:use_args, a: :a, b: :b) do
163
- @i_can = true
171
+ scope "#perform_unless" do
172
+ let(:authorizator) { BasicAuthorizator.new }
173
+ spec "executes the block if it is allowed" do
174
+ authorizator.perform_unless(:can) do
175
+ @i_can = true
176
+ end
177
+
178
+ ! defined? @i_can
164
179
  end
165
180
 
166
- !! defined? @i_can
181
+ spec "doesn't execute the block if it isn't allowed" do
182
+ authorizator.perform_unless(:cant) do
183
+ @i_can = true
184
+ end
185
+
186
+ !! defined? @i_can
187
+ end
188
+
189
+ spec "passes the arguments" do
190
+ authorizator.perform_unless(:use_args, a: :a, b: :b) do
191
+ @i_can = true
192
+ end
193
+
194
+ ! defined? @i_can
195
+ end
167
196
  end
168
197
  end
169
198
 
@@ -310,11 +339,11 @@ scope YouShallNotPass::Authorizator do
310
339
  class DslAuthorizator < YouShallNotPass::Authorizator
311
340
  attribute :user
312
341
  attribute :pass
313
-
314
- authorize(:true) { true }
315
- authorize(:false) { false }
316
342
 
317
- authorize(:login) { user == pass}
343
+ policy(:true) { true }
344
+ policy(:false) { false }
345
+
346
+ policy(:login) { user == pass}
318
347
  end
319
348
 
320
349
  let(:authorizator) { DslAuthorizator.new(user: "fede", pass: "fede") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: you_shall_not_pass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti