Module: Challah::Rolls::Role::InstanceMethods
- Defined in:
- lib/challah/rolls/role.rb
Instance Method Summary collapse
-
#has(permision_or_key) ⇒ Boolean
(also: #permission?)
Does this role have the given
Permission
? Pass in a Permission instance, or a permission key to check for its existance. -
#method_missing(sym, *args, &block) ⇒ Object
Customized
method_missing
call that can be used to detect whether a role has a given permission. -
#permission_keys ⇒ Array
Grab all permission keys for this
Role
. -
#permission_keys=(keys) ⇒ Array
Set the permission keys that this role can access.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
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.
168 169 170 171 |
# File 'lib/challah/rolls/role.rb', line 168 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
#has(permision_or_key) ⇒ Boolean 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.
154 155 156 157 |
# File 'lib/challah/rolls/role.rb', line 154 def has(permision_or_key) symbolized_key = ::Permission === permision_or_key ? permision_or_key[:key] : permision_or_key.to_s .include?(symbolized_key) end |
#permission_keys ⇒ Array
Grab all permission keys for this Role
Note that this returns permission keys, not Permission instances.
130 131 132 |
# File 'lib/challah/rolls/role.rb', line 130 def @permission_keys ||= self..collect(&:key) end |
#permission_keys=(keys) ⇒ Array
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.
142 143 144 145 |
# File 'lib/challah/rolls/role.rb', line 142 def (keys) @permission_keys = keys @permission_keys end |