role_authorization 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/role_authorization/user.rb +20 -16
- data/lib/role_authorization/version.rb +1 -1
- metadata +1 -1
@@ -48,30 +48,34 @@ module RoleAuthorization
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def roles(
|
52
|
-
|
51
|
+
def roles(scopes = nil)
|
52
|
+
scopes = [scopes] unless scopes.is_a? Array
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
if
|
59
|
-
|
60
|
-
array << value.values
|
61
|
-
else
|
62
|
-
array << value unless value.nil?
|
63
|
-
end
|
54
|
+
scopes.map do |scope|
|
55
|
+
scope, scope_id = scope_with(scope)
|
56
|
+
|
57
|
+
(serialized_roles || {}).inject([]) do |array, (key, value)|
|
58
|
+
if key == :global && scope.nil?
|
59
|
+
array << value
|
64
60
|
else
|
61
|
+
if scope.nil? || (key == scope.to_sym && scope_id.nil?)
|
62
|
+
if value.is_a?(Hash)
|
63
|
+
array << value.values
|
64
|
+
else
|
65
|
+
array << value unless value.nil?
|
66
|
+
end
|
67
|
+
else
|
65
68
|
array << value[scope_id] unless scope_id.nil?
|
69
|
+
end
|
66
70
|
end
|
67
|
-
end
|
68
71
|
|
69
|
-
|
72
|
+
array
|
73
|
+
end
|
70
74
|
end.flatten.uniq
|
71
75
|
end
|
72
76
|
|
73
|
-
def has_role?(role,
|
74
|
-
roles(
|
77
|
+
def has_role?(role, scopes = nil)
|
78
|
+
roles(scopes).include?(role)
|
75
79
|
end
|
76
80
|
|
77
81
|
def <<(value)
|