role_authorization 0.2.0 → 0.2.1
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.
- data/lib/role_authorization/user.rb +16 -0
- data/lib/role_authorization/version.rb +1 -1
- metadata +1 -1
@@ -34,6 +34,18 @@ module RoleAuthorization
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def scope_ids_from(*roles)
|
38
|
+
(serialized_roles || {}).inject([]) do |array, (key, value)|
|
39
|
+
next if key == :global
|
40
|
+
next unless value.is_a?(Hash)
|
41
|
+
|
42
|
+
value.each_pair do |key, value|
|
43
|
+
array << key.to_i unless (value & roles).empty?
|
44
|
+
end
|
45
|
+
array
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
def roles(scope = nil)
|
38
50
|
scope, scope_id = scope_with(scope)
|
39
51
|
|
@@ -56,6 +68,10 @@ module RoleAuthorization
|
|
56
68
|
roles(scope).include?(role)
|
57
69
|
end
|
58
70
|
|
71
|
+
def <<(value)
|
72
|
+
enroll(value)
|
73
|
+
end
|
74
|
+
|
59
75
|
# adds a role to the user
|
60
76
|
def enroll(role_name, scope = nil)
|
61
77
|
return true if has_role?(role_name.to_sym, scope)
|