authoraise 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/authoraise/version.rb +1 -1
- data/lib/authoraise.rb +6 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f24e784a52e7c2725bfc0eade0fe98a1909fcd4
|
4
|
+
data.tar.gz: cb91b76b2dea79aac821e178bfa288947d7d5f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c60e2997ea5f5dabd5773a09315c9d81015b2064d85ad4d4d7b301a7ac410c17f249ab51e3ced94db87c75b1447162bc9329899ecf4a8f3911ccffa6b20601b
|
7
|
+
data.tar.gz: 922747b570f4d91313c363af7e394faf7f7cb853863808b2f2c2d7ed633d3b850d75b1bf7c18f0495c41166fe511e3172ec7d0f259c5410862b3d1e35564c2ec
|
data/README.md
CHANGED
@@ -54,9 +54,9 @@ Authoraise.strict_mode = true
|
|
54
54
|
# In stict mode any missing key raises an error, even if other checks passed.
|
55
55
|
authorize(user: 'sammy') do |policy|
|
56
56
|
policy.allow { |user| user == 'sammy' }
|
57
|
-
policy.allow { |post| post
|
57
|
+
policy.allow { |post| post == 'foo' }
|
58
58
|
end
|
59
|
-
# => Authoraise::Error:
|
59
|
+
# => Authoraise::Error: Strict mode found missing keys: [:post]
|
60
60
|
~~~
|
61
61
|
|
62
62
|
## Installation
|
data/lib/authoraise/version.rb
CHANGED
data/lib/authoraise.rb
CHANGED
@@ -7,9 +7,9 @@ module Authoraise
|
|
7
7
|
class << self; attr_accessor :strict_mode end
|
8
8
|
|
9
9
|
def authorize(options = {})
|
10
|
-
policy = Policy.new
|
10
|
+
policy = Policy.new
|
11
11
|
yield(policy)
|
12
|
-
policy.authorize
|
12
|
+
policy.authorize(options)
|
13
13
|
end
|
14
14
|
|
15
15
|
class Check
|
@@ -36,8 +36,7 @@ module Authoraise
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class Policy
|
39
|
-
def initialize
|
40
|
-
@options = options
|
39
|
+
def initialize
|
41
40
|
@checks = []
|
42
41
|
@mode = :any
|
43
42
|
end
|
@@ -47,15 +46,15 @@ module Authoraise
|
|
47
46
|
Check.new(procedure.parameters.map(&:last), procedure)
|
48
47
|
end
|
49
48
|
|
50
|
-
def authorize
|
49
|
+
def authorize(options = {})
|
51
50
|
raise Error, 'Policy is empty' if @checks.empty?
|
52
|
-
given_keys =
|
51
|
+
given_keys = options.keys.to_set
|
53
52
|
assert_all_keys_match(given_keys) if Authoraise.strict_mode
|
54
53
|
missing_keys = Set.new
|
55
54
|
|
56
55
|
@checks.each do |check|
|
57
56
|
if check.required_keys.subset?(given_keys)
|
58
|
-
return true if check.(
|
57
|
+
return true if check.(options)
|
59
58
|
else
|
60
59
|
missing_keys += check.missing_keys(given_keys)
|
61
60
|
end
|