Module: Roleable
Instance Method Summary collapse
- #hasnt_role!(role) ⇒ Object (also: #remove_role, #delete_role, #destroy_role)
- #role!(role) ⇒ Object (also: #has_role!, #add_role)
- #role?(role) ⇒ Boolean (also: #has_role?, #is?)
Instance Method Details
#hasnt_role!(role) ⇒ Object Also known as: remove_role, delete_role, destroy_role
32 33 34 35 36 37 38 39 40 |
# File 'app/models/roleable.rb', line 32 def hasnt_role!(role) self.send(:"roles=", []) if !self.roles if self.has_role? role.to_s self.roles.delete(role) self.update_attribute(:roles, self.roles) end end |
#role!(role) ⇒ Object Also known as: has_role!, add_role
20 21 22 23 24 25 26 27 |
# File 'app/models/roleable.rb', line 20 def role!(role) self.send(:"roles=", []) if !self.roles if !self.has_role? role self.roles << role.to_s self.update_attribute(:roles, self.roles) end end |
#role?(role) ⇒ Boolean Also known as: has_role?, is?
10 11 12 13 14 15 16 |
# File 'app/models/roleable.rb', line 10 def role?(role) if self.roles self.roles.include? role.to_s else false end end |