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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff264efe0dc106fb920967bfa713da23337f8c2b
|
4
|
+
data.tar.gz: 53289da65c93a55c9e54e26eecf1073c8366f9c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
65
|
+
def self.policy(name, &block)
|
62
66
|
__dsl_policies__[name] = block
|
63
67
|
end
|
64
68
|
|
@@ -128,7 +128,7 @@ scope YouShallNotPass::Authorizator do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
scope "
|
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
|
-
|
143
|
+
scope "#perform_if" do
|
144
|
+
let(:authorizator) { BasicAuthorizator.new }
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
151
|
-
|
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
|
-
|
154
|
-
authorizator.perform_for(:cant) do
|
155
|
-
@i_can = true
|
159
|
+
! defined? @i_can
|
156
160
|
end
|
157
161
|
|
158
|
-
|
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
|
-
|
162
|
-
|
163
|
-
|
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
|
-
|
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
|
-
|
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") }
|