you_shall_not_pass 0.2.1 → 0.3.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e20c5005c72aeb739cd71a80056cf3dd04db7364
|
4
|
+
data.tar.gz: a2d58f582174be34a55deaf1ccce28a13d446b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b8a0d94504f61cb291fa8b82887d1451cbc9b70bdda75c34514ce127d430ffc9a3f7b37c29bf198d1973707b1b38ba7c47a081e1950970b70a813d691523c41
|
7
|
+
data.tar.gz: c02af7ba490bdc94d797905d58232bb8ca06a3b713ac50c9504ebf10d804a551ed1bc955e53058646378e08e8dbf848eb7003f89020e0e223db3cd966a1c85b0
|
@@ -17,6 +17,14 @@ module YouShallNotPass
|
|
17
17
|
break_down_can(permission, exception, **args)
|
18
18
|
end
|
19
19
|
|
20
|
+
def can_all?(*permissions, **args)
|
21
|
+
permissions.all? { |permission| can?(permission, **args)}
|
22
|
+
end
|
23
|
+
|
24
|
+
def can_any?(*permissions, **args)
|
25
|
+
permissions.any? { |permission| can?(permission, **args)}
|
26
|
+
end
|
27
|
+
|
20
28
|
def break_down_can(permission, exception, **args)
|
21
29
|
case permission
|
22
30
|
when /_and_/
|
@@ -39,6 +47,22 @@ module YouShallNotPass
|
|
39
47
|
yield unless can?(permission, **args)
|
40
48
|
end
|
41
49
|
|
50
|
+
def perform_if_all(*permissions, **args)
|
51
|
+
yield if can_all?(*permissions, **args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def perform_unless_all(*permissions, **args)
|
55
|
+
yield unless can_all?(*permissions, **args)
|
56
|
+
end
|
57
|
+
|
58
|
+
def perform_if_any(*permissions, **args)
|
59
|
+
yield if can_any?(*permissions, **args)
|
60
|
+
end
|
61
|
+
|
62
|
+
def perform_unless_any(*permissions, **args)
|
63
|
+
yield unless can_any?(*permissions, **args)
|
64
|
+
end
|
65
|
+
|
42
66
|
def policies
|
43
67
|
@policies ||= __set_policies__
|
44
68
|
end
|
@@ -2,6 +2,20 @@ require "spec_helper"
|
|
2
2
|
require "you_shall_not_pass/authorizator"
|
3
3
|
|
4
4
|
scope YouShallNotPass::Authorizator do
|
5
|
+
|
6
|
+
class BasicAuthorizator < YouShallNotPass::Authorizator
|
7
|
+
def policies
|
8
|
+
{
|
9
|
+
can: true,
|
10
|
+
can2: true,
|
11
|
+
cant: false,
|
12
|
+
cant2: false,
|
13
|
+
|
14
|
+
use_args: -> (**args) { args.all? { |k, v| k == v } }
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
scope "#can?" do
|
6
20
|
scope "no policies" do
|
7
21
|
spec "no policies defined" do
|
@@ -13,6 +27,46 @@ scope YouShallNotPass::Authorizator do
|
|
13
27
|
end
|
14
28
|
end
|
15
29
|
|
30
|
+
scope "can multiple" do
|
31
|
+
let(:authorizator) { BasicAuthorizator.new }
|
32
|
+
|
33
|
+
spec "can_all? authorizes if all policies pass" do
|
34
|
+
authorizator.can_all?(:can, :can2)
|
35
|
+
end
|
36
|
+
|
37
|
+
spec "can_all? doesn't authorize unless all policies pass" do
|
38
|
+
authorizator.can_all?(:can, :cant) == false
|
39
|
+
end
|
40
|
+
|
41
|
+
spec "can_any? authorizes if any of the policies pass" do
|
42
|
+
authorizator.can_any?(:can, :cant)
|
43
|
+
end
|
44
|
+
|
45
|
+
spec "can_any? doesn't authorize if all the policies return false" do
|
46
|
+
authorizator.can_any?(:cant, :cant2) == false
|
47
|
+
end
|
48
|
+
|
49
|
+
scope "with arguments" do
|
50
|
+
let(:authorizator) { BasicAuthorizator.new }
|
51
|
+
|
52
|
+
spec do
|
53
|
+
authorizator.can_all?(:use_args, :can2, a: :a)
|
54
|
+
end
|
55
|
+
|
56
|
+
spec do
|
57
|
+
authorizator.can_all?(:use_args, :can, a: false) == false
|
58
|
+
end
|
59
|
+
|
60
|
+
spec do
|
61
|
+
authorizator.can_any?(:use_args, :can2, a: :a)
|
62
|
+
end
|
63
|
+
|
64
|
+
spec do
|
65
|
+
authorizator.can_all?(:use_args, :cant, a: false) == false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
16
70
|
scope "lambdas, procs and other callables" do
|
17
71
|
class Action
|
18
72
|
def initialize(val)
|
@@ -129,17 +183,6 @@ scope YouShallNotPass::Authorizator do
|
|
129
183
|
end
|
130
184
|
|
131
185
|
scope "performing" do
|
132
|
-
class BasicAuthorizator < YouShallNotPass::Authorizator
|
133
|
-
def policies
|
134
|
-
{
|
135
|
-
can: true,
|
136
|
-
cant: false,
|
137
|
-
|
138
|
-
use_args: -> (**args) { args.all? { |k, v| k == v } }
|
139
|
-
}
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
186
|
scope "#perform_if" do
|
144
187
|
let(:authorizator) { BasicAuthorizator.new }
|
145
188
|
|
@@ -194,6 +237,76 @@ scope YouShallNotPass::Authorizator do
|
|
194
237
|
! defined? @i_can
|
195
238
|
end
|
196
239
|
end
|
240
|
+
|
241
|
+
scope "perform multiple" do
|
242
|
+
let(:authorizator) { BasicAuthorizator.new }
|
243
|
+
|
244
|
+
spec "#perform_if_all" do
|
245
|
+
authorizator.perform_if_all(:can, :can2) do
|
246
|
+
@i_can = true
|
247
|
+
end
|
248
|
+
|
249
|
+
!! defined? @i_can
|
250
|
+
end
|
251
|
+
|
252
|
+
spec "#perform_unless_all" do
|
253
|
+
authorizator.perform_unless_all(:can, :cant) do
|
254
|
+
@i_can = true
|
255
|
+
end
|
256
|
+
|
257
|
+
!! defined? @i_can
|
258
|
+
end
|
259
|
+
|
260
|
+
spec "not #perform_if_all" do
|
261
|
+
authorizator.perform_if_all(:can, :cant) do
|
262
|
+
@i_can = true
|
263
|
+
end
|
264
|
+
|
265
|
+
! defined? @i_can
|
266
|
+
end
|
267
|
+
|
268
|
+
spec "not #perform_unless_all" do
|
269
|
+
authorizator.perform_unless_all(:can, :can2) do
|
270
|
+
@i_can = true
|
271
|
+
end
|
272
|
+
|
273
|
+
! defined? @i_can
|
274
|
+
end
|
275
|
+
|
276
|
+
spec "#perform_if_any" do
|
277
|
+
authorizator.perform_if_any(:can, :can2) do
|
278
|
+
@i_can = true
|
279
|
+
end
|
280
|
+
|
281
|
+
!! defined? @i_can
|
282
|
+
end
|
283
|
+
|
284
|
+
spec "#perform_unless_any" do
|
285
|
+
authorizator.perform_unless_any(:cant, :cant2) do
|
286
|
+
@i_can = true
|
287
|
+
end
|
288
|
+
|
289
|
+
!! defined? @i_can
|
290
|
+
end
|
291
|
+
|
292
|
+
spec "not #perform_if_any" do
|
293
|
+
authorizator.perform_if_any(:cant, :cant2) do
|
294
|
+
@i_can = true
|
295
|
+
end
|
296
|
+
|
297
|
+
! defined? @i_can
|
298
|
+
end
|
299
|
+
|
300
|
+
spec "not #perform_unless_any" do
|
301
|
+
authorizator.perform_unless_any(:can, :can2) do
|
302
|
+
@i_can = true
|
303
|
+
end
|
304
|
+
|
305
|
+
! defined? @i_can
|
306
|
+
end
|
307
|
+
|
308
|
+
|
309
|
+
end
|
197
310
|
end
|
198
311
|
|
199
312
|
scope "conditional policies" do
|
data/you_shall_not_pass.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "matest", "~> 1.7.
|
23
|
+
spec.add_development_dependency "matest", "~> 1.7.2"
|
24
24
|
|
25
25
|
spec.add_dependency "callable", "~> 0.0.5"
|
26
26
|
spec.add_dependency "fattr", "~> 2.2.2"
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.7.
|
47
|
+
version: 1.7.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.7.
|
54
|
+
version: 1.7.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: callable
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|