six 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/lib/six.rb +55 -58
- metadata +10 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1baeab3f89187feb29f13656f97feff16289a991
|
4
|
+
data.tar.gz: 875ed69454035cfbe8fe13f64f9363e3ab68c64d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 93b16cd2977997d367fce2b219d68834e786891df1709f2d0aba2f4108a7bc99376f08db3e4ac96d7a3342e1f23235fbe016604f1cfbba971fc087ac13dda0e4
|
7
|
+
data.tar.gz: ed04447bf3923dbd24f848287109da5f62b145e3ea34a5e37ee8dfaeb97fbe9bb8b48127e7459149cb79b6de44ac0e8b5e9bfaf92550bbbda58ef4c289521680
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 Dmitriy Zaporozhets
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/lib/six.rb
CHANGED
@@ -20,15 +20,15 @@ class Six
|
|
20
20
|
attr_reader :rules_packs
|
21
21
|
attr_reader :current_rule_pack
|
22
22
|
|
23
|
-
# Initialize ability object
|
24
|
-
#
|
23
|
+
# Initialize ability object
|
24
|
+
#
|
25
25
|
# == Parameters:
|
26
26
|
# packs::
|
27
|
-
# A Hash or rules to add with initializtion
|
28
|
-
#
|
27
|
+
# A Hash or rules to add with initializtion
|
28
|
+
#
|
29
29
|
# == Returns:
|
30
30
|
# self
|
31
|
-
#
|
31
|
+
#
|
32
32
|
def initialize(packs={})
|
33
33
|
raise InitializeArgumentError.new unless packs.kind_of?(Hash)
|
34
34
|
|
@@ -38,15 +38,15 @@ class Six
|
|
38
38
|
packs.each { |key, pack| add_pack!(key, pack) }
|
39
39
|
end
|
40
40
|
|
41
|
-
# Set current pack from stored packs by key
|
42
|
-
#
|
41
|
+
# Set current pack from stored packs by key
|
42
|
+
#
|
43
43
|
# == Parameters:
|
44
44
|
# name::
|
45
|
-
# A Symbol declaring the key name of stored pack
|
46
|
-
#
|
45
|
+
# A Symbol declaring the key name of stored pack
|
46
|
+
#
|
47
47
|
# == Returns:
|
48
|
-
# self or false
|
49
|
-
#
|
48
|
+
# self or false
|
49
|
+
#
|
50
50
|
def use_pack(name)
|
51
51
|
if pack_exist?(name)
|
52
52
|
@current_rule_pack = name.to_sym
|
@@ -54,53 +54,53 @@ class Six
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
# Same as use but raise exception if no pack found
|
57
|
+
# Same as use but raise exception if no pack found
|
58
58
|
def use_pack!(name)
|
59
59
|
use_pack(name) ? self : raise_no_such_pack
|
60
60
|
end
|
61
61
|
|
62
|
-
# Add pack to authorization class
|
63
|
-
#
|
62
|
+
# Add pack to authorization class
|
63
|
+
#
|
64
64
|
# == Parameters:
|
65
65
|
# name::
|
66
|
-
# A Symbol declaring the key name of stored pack
|
66
|
+
# A Symbol declaring the key name of stored pack
|
67
67
|
# pack::
|
68
|
-
# Any kind of object responding to allowed method
|
69
|
-
#
|
68
|
+
# Any kind of object responding to allowed method
|
69
|
+
#
|
70
70
|
# == Returns:
|
71
|
-
# true or false
|
72
|
-
#
|
71
|
+
# true or false
|
72
|
+
#
|
73
73
|
def add_pack(name, pack)
|
74
74
|
rules_packs[name.to_sym] = pack if valid_rules_object?(pack)
|
75
75
|
end
|
76
76
|
|
77
|
-
# Same as add_pack but raise exception if pack is invalid
|
77
|
+
# Same as add_pack but raise exception if pack is invalid
|
78
78
|
def add_pack!(name, pack)
|
79
79
|
add_pack(name, pack) || raise_incorrect_pack_object
|
80
80
|
end
|
81
81
|
|
82
82
|
# Add pack to authorization class w/o key
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# == Parameters:
|
85
85
|
# pack::
|
86
|
-
# Any kind of object responding to allowed method
|
87
|
-
#
|
86
|
+
# Any kind of object responding to allowed method
|
87
|
+
#
|
88
88
|
# == Returns:
|
89
|
-
# true or raise exception
|
90
|
-
#
|
89
|
+
# true or raise exception
|
90
|
+
#
|
91
91
|
def <<(pack)
|
92
92
|
add_pack!(pack.object_id.to_s, pack)
|
93
93
|
end
|
94
94
|
|
95
|
-
# Remove pack from authorization class
|
96
|
-
#
|
95
|
+
# Remove pack from authorization class
|
96
|
+
#
|
97
97
|
# == Parameters:
|
98
98
|
# name::
|
99
|
-
# A Symbol declaring the key name of stored pack
|
100
|
-
#
|
99
|
+
# A Symbol declaring the key name of stored pack
|
100
|
+
#
|
101
101
|
# == Returns:
|
102
|
-
# true or false
|
103
|
-
#
|
102
|
+
# true or false
|
103
|
+
#
|
104
104
|
def remove_pack(name)
|
105
105
|
if pack_exist?(name)
|
106
106
|
@current_rule_pack = nil if rules_packs[name.to_sym] == @current_rule_pack
|
@@ -113,56 +113,53 @@ class Six
|
|
113
113
|
remove_pack(name) || raise_no_such_pack
|
114
114
|
end
|
115
115
|
|
116
|
-
# Check if object for rule pack is valid
|
117
|
-
#
|
116
|
+
# Check if object for rule pack is valid
|
117
|
+
#
|
118
118
|
# == Parameters:
|
119
119
|
# pack::
|
120
|
-
# Any kind of object responding to allowed method
|
121
|
-
#
|
120
|
+
# Any kind of object responding to allowed method
|
121
|
+
#
|
122
122
|
# == Returns:
|
123
|
-
# true or false
|
124
|
-
#
|
123
|
+
# true or false
|
124
|
+
#
|
125
125
|
def valid_rules_object?(object)
|
126
|
-
object.respond_to?(:allowed)
|
127
|
-
object.send(:allowed, nil, nil).kind_of?(Array)
|
128
|
-
rescue
|
129
|
-
false
|
126
|
+
object.respond_to?(:allowed)
|
130
127
|
end
|
131
128
|
|
132
|
-
# Check if authorization class has pack with such name
|
133
|
-
#
|
129
|
+
# Check if authorization class has pack with such name
|
130
|
+
#
|
134
131
|
# == Parameters:
|
135
132
|
# name::
|
136
|
-
# A Symbol declaring the key name of stored pack
|
137
|
-
#
|
133
|
+
# A Symbol declaring the key name of stored pack
|
134
|
+
#
|
138
135
|
# == Returns:
|
139
|
-
# true or false
|
140
|
-
#
|
136
|
+
# true or false
|
137
|
+
#
|
141
138
|
def pack_exist?(name)
|
142
139
|
rules_packs.has_key?(name.to_sym)
|
143
140
|
end
|
144
141
|
|
145
142
|
# Check if authorization class allow access for object to subject
|
146
|
-
# using selected pack or all stored.
|
147
|
-
# Basically this method
|
143
|
+
# using selected pack or all stored.
|
144
|
+
# Basically this method
|
148
145
|
# 1. send :allowed for every stored object in packs and pass object & subject
|
149
146
|
# 2. check if any of results include allowed action
|
150
|
-
#
|
147
|
+
#
|
151
148
|
# == Parameters:
|
152
149
|
# action::
|
153
|
-
# Action name to check for access
|
150
|
+
# Action name to check for access
|
154
151
|
# object::
|
155
|
-
# object trying to access resource
|
152
|
+
# object trying to access resource
|
156
153
|
# subject::
|
157
154
|
# resource
|
158
|
-
#
|
155
|
+
#
|
159
156
|
# == Returns:
|
160
|
-
# true or false
|
161
|
-
#
|
157
|
+
# true or false
|
158
|
+
#
|
162
159
|
def allowed?(object, actions, subject)
|
163
160
|
# if multiple actions passed
|
164
161
|
# check all actions to be allowed
|
165
|
-
if actions.respond_to?(:each)
|
162
|
+
if actions.respond_to?(:each)
|
166
163
|
actions.all? { |action| action_included?(object, action, subject) }
|
167
164
|
else
|
168
165
|
# single action check
|
@@ -170,7 +167,7 @@ class Six
|
|
170
167
|
end
|
171
168
|
end
|
172
169
|
|
173
|
-
# Reset current used rule pack so auth class use
|
170
|
+
# Reset current used rule pack so auth class use
|
174
171
|
# global allowed? for new request
|
175
172
|
def reset_use
|
176
173
|
@current_rule_pack = nil
|
@@ -181,7 +178,7 @@ class Six
|
|
181
178
|
def action_included?(object, action, subject)
|
182
179
|
if current_rule_pack
|
183
180
|
rules_packs[current_rule_pack].allowed(object, subject).include?(action)
|
184
|
-
else
|
181
|
+
else
|
185
182
|
rules_packs.values.map { |rp| rp.allowed(object, subject) }.flatten.include?(action)
|
186
183
|
end
|
187
184
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: six
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dmitriy Zaporozhets
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Very simple authorization gem
|
15
14
|
email: dmitriy.zaporozhets@gmail.com
|
@@ -17,29 +16,30 @@ executables: []
|
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
19
|
+
- LICENSE
|
20
20
|
- lib/six.rb
|
21
21
|
homepage: https://github.com/randx/six
|
22
|
-
licenses:
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
23
25
|
post_install_message:
|
24
26
|
rdoc_options: []
|
25
27
|
require_paths:
|
26
28
|
- lib
|
27
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version:
|
41
|
+
rubygems_version: 2.6.14
|
42
42
|
signing_key:
|
43
|
-
specification_version:
|
43
|
+
specification_version: 4
|
44
44
|
summary: six
|
45
45
|
test_files: []
|