Module: Challah::AuthableRole::InstanceMethods
- Defined in:
- lib/challah/authable/role.rb
Instance Method Summary (collapse)
-
- (Boolean) has(permision_or_key)
(also: #permission?)
Does this role have the given Permission? Pass in a Permission instance, or a permission key to check for its existance.
-
- (Object) method_missing(sym, *args, &block)
Customized method_missing call that can be used to detect whether a role has a given permission.
-
- (Array) permission_keys
Grab all permission keys for this Role.
-
- (Array) permission_keys=(keys)
Set the permission keys that this role can access.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(sym, *args, &block)
Customized method_missing call that can be used to detect whether a role has a given permission. This passes a key to the #has method.
149 150 151 152 |
# File 'lib/challah/authable/role.rb', line 149 def method_missing(sym, *args, &block) return has(sym.to_s.gsub(/\?/, '')) if sym.to_s =~ /^[a-z0-9_]*\?$/ super(sym, *args, &block) end |
Instance Method Details
- (Boolean) has(permision_or_key) Also known as: permission?
Does this role have the given Permission? Pass in a Permission instance, or a permission key to check for its existance.
135 136 137 138 |
# File 'lib/challah/authable/role.rb', line 135 def has(permision_or_key) symbolized_key = ::Permission === permision_or_key ? permision_or_key[:key] : permision_or_key.to_s .include?(symbolized_key) end |
- (Array) permission_keys
Grab all permission keys for this Role
Note that this returns permission keys, not Permission instances.
111 112 113 |
# File 'lib/challah/authable/role.rb', line 111 def @permission_keys ||= self..collect(&:key) end |
- (Array) permission_keys=(keys)
Set the permission keys that this role can access. This temporarily updates the permission keys for the Role instance, but changes are not saved until the model has been saved.
123 124 125 126 |
# File 'lib/challah/authable/role.rb', line 123 def (keys) @permission_keys = keys @permission_keys end |