you_shall_not_pass 0.3.1 → 0.4.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 +4 -4
- data/.travis.yml +1 -0
- data/lib/you_shall_not_pass/authorizator.rb +18 -33
- data/lib/you_shall_not_pass/version.rb +1 -1
- data/spec/you_shall_not_pass/authorizator_spec.rb +16 -32
- data/you_shall_not_pass.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e812f579e8e53dd88d7baf6709a796ca5fb5789
|
4
|
+
data.tar.gz: 1afa8fbd75a3860ab0c177dd7b1bcbb02d48e225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c57d8fdbc4e21e840b1254c982e281d6eca84cb697a7357002b5048acfce92a99beb13df5ef9ee63b7859db037e01f02d6b4a018a6f6153e9ab24abdc7fff05f
|
7
|
+
data.tar.gz: bf93d4ac763e4d5437a51c70966a5ff78bfb95f4b172d25d99978ef04fc76a934682e5cff24cdf5cd4d900ac0692cc5b9c56ea7266a4a9ffb480d9537ccd2864
|
data/.travis.yml
CHANGED
@@ -13,8 +13,6 @@ module YouShallNotPass
|
|
13
13
|
Array(policies.fetch(permission)).all? do |policy|
|
14
14
|
Callable(policy).call(**args) == true
|
15
15
|
end
|
16
|
-
rescue KeyError => exception
|
17
|
-
break_down_can(permission, exception, **args)
|
18
16
|
end
|
19
17
|
|
20
18
|
def can_all?(*permissions, **args)
|
@@ -25,20 +23,6 @@ module YouShallNotPass
|
|
25
23
|
permissions.any? { |permission| can?(permission, **args)}
|
26
24
|
end
|
27
25
|
|
28
|
-
def break_down_can(permission, exception, **args)
|
29
|
-
case permission
|
30
|
-
when /_and_/
|
31
|
-
permission.to_s.split("_and_").all? { |policy| can?(policy.to_sym, **args)}
|
32
|
-
when /_or_/
|
33
|
-
permission.to_s.split("_or_").any? { |policy| can?(policy.to_sym, **args)}
|
34
|
-
when /\Anot_/
|
35
|
-
policy = permission.to_s.gsub(/\Anot_/, "")
|
36
|
-
! can?(policy.to_sym, **args)
|
37
|
-
else
|
38
|
-
raise exception
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
26
|
def perform_if(permission, **args)
|
43
27
|
yield if can?(permission, **args)
|
44
28
|
end
|
@@ -68,31 +52,32 @@ module YouShallNotPass
|
|
68
52
|
end
|
69
53
|
|
70
54
|
private
|
55
|
+
def self.policy(name, &block)
|
56
|
+
__dsl_policies__[name] = proc { block }
|
57
|
+
end
|
71
58
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
the_policies.merge!( self.class.__dsl_policies__.each_with_object({}) { |policy, h|
|
78
|
-
block = policy.last
|
79
|
-
h[policy.first] = instance_eval(&block)
|
80
|
-
})
|
59
|
+
def self.attribute(attr)
|
60
|
+
fattr attr
|
61
|
+
end
|
62
|
+
private_class_method :attribute
|
81
63
|
|
82
|
-
|
64
|
+
def __set_policies__
|
65
|
+
__method_policies__.merge!(__dsl_policies__)
|
83
66
|
end
|
84
67
|
|
85
|
-
def
|
86
|
-
|
68
|
+
def __method_policies__
|
69
|
+
methods.grep(/_policies\z/).
|
70
|
+
each_with_object({}) { |name, res| res.merge!(send(name)) }
|
87
71
|
end
|
88
72
|
|
89
|
-
def
|
90
|
-
__dsl_policies__
|
73
|
+
def __dsl_policies__
|
74
|
+
self.class.__dsl_policies__. each_with_object({}) { |(name, value), res|
|
75
|
+
res[name] = instance_eval(&value)
|
76
|
+
}
|
91
77
|
end
|
92
78
|
|
93
|
-
def self.
|
94
|
-
|
79
|
+
def self.__dsl_policies__
|
80
|
+
@__dsl_policies__ ||= {}
|
95
81
|
end
|
96
|
-
private_class_method :attribute
|
97
82
|
end
|
98
83
|
end
|
@@ -90,9 +90,13 @@ scope YouShallNotPass::Authorizator do
|
|
90
90
|
can_action: Action.new(true),
|
91
91
|
cant_action: Action.new(false),
|
92
92
|
|
93
|
+
can_true_or_false: true || false,
|
94
|
+
cant_true_and_false: true && false,
|
95
|
+
|
93
96
|
can_true: true,
|
94
97
|
cant_false: false,
|
95
98
|
|
99
|
+
|
96
100
|
can_array: [ true, proc { true }, true ],
|
97
101
|
cant_array: [ true, false, true ],
|
98
102
|
}
|
@@ -133,6 +137,18 @@ scope YouShallNotPass::Authorizator do
|
|
133
137
|
! authorizator.can?(:cant_false)
|
134
138
|
end
|
135
139
|
|
140
|
+
spec "reject false" do
|
141
|
+
! authorizator.can?(:cant_false)
|
142
|
+
end
|
143
|
+
|
144
|
+
spec "allow true or false" do
|
145
|
+
authorizator.can?(:can_true_or_false)
|
146
|
+
end
|
147
|
+
|
148
|
+
spec "reject true and false" do
|
149
|
+
! authorizator.can?(:cant_true_and_false)
|
150
|
+
end
|
151
|
+
|
136
152
|
spec "allow array" do
|
137
153
|
authorizator.can?(:can_array)
|
138
154
|
end
|
@@ -323,38 +339,6 @@ scope YouShallNotPass::Authorizator do
|
|
323
339
|
|
324
340
|
let(:authorizator) { NumberAuthorizator.new }
|
325
341
|
|
326
|
-
spec "allow _and_" do
|
327
|
-
authorizator.can?(:one_and_two)
|
328
|
-
end
|
329
|
-
|
330
|
-
spec "reject _and_" do
|
331
|
-
! authorizator.can?(:one_and_three)
|
332
|
-
end
|
333
|
-
|
334
|
-
spec "allow _or_" do
|
335
|
-
authorizator.can?(:one_or_two)
|
336
|
-
end
|
337
|
-
|
338
|
-
spec "reject _or_" do
|
339
|
-
! authorizator.can?(:three_or_four)
|
340
|
-
end
|
341
|
-
|
342
|
-
spec "allow not_" do
|
343
|
-
authorizator.can?(:not_three)
|
344
|
-
end
|
345
|
-
|
346
|
-
spec "reject not_" do
|
347
|
-
! authorizator.can?(:not_one)
|
348
|
-
end
|
349
|
-
|
350
|
-
spec "allow _and_or_" do
|
351
|
-
authorizator.can?(:one_and_two_or_three)
|
352
|
-
end
|
353
|
-
|
354
|
-
spec "reject _and_or_" do
|
355
|
-
! authorizator.can?(:one_and_three_or_four)
|
356
|
-
end
|
357
|
-
|
358
342
|
scope "regular policies vs conditional policies" do
|
359
343
|
class ConditionalAuthorizator < YouShallNotPass::Authorizator
|
360
344
|
def policies
|
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.4"
|
24
24
|
|
25
25
|
spec.add_dependency "callable", "~> 0.0.5"
|
26
26
|
spec.add_dependency "fattr", "~> 2.2.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.7.
|
47
|
+
version: 1.7.4
|
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.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: callable
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.6.10
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Simple authorization library.
|