Module: Mongoid::Document::Roleable::InstanceMethods
- Defined in:
- lib/mongoid-simple-roles.rb
Instance Method Summary collapse
- #add_role(role) ⇒ Object
- #has_role?(role) ⇒ Boolean
- #remove_role(role) ⇒ Object
- #with_roles=(roles) ⇒ Object
Instance Method Details
#add_role(role) ⇒ Object
19 20 21 22 |
# File 'lib/mongoid-simple-roles.rb', line 19 def add_role(role) self.roles = Array.new if self.roles.nil? self.roles << role if role end |
#has_role?(role) ⇒ Boolean
24 25 26 |
# File 'lib/mongoid-simple-roles.rb', line 24 def has_role?(role) self.roles.include?(role) end |
#remove_role(role) ⇒ Object
28 29 30 |
# File 'lib/mongoid-simple-roles.rb', line 28 def remove_role(role) self.roles.delete_if { |r| r.casecmp(role) == 0 } end |
#with_roles=(roles) ⇒ Object
15 16 17 |
# File 'lib/mongoid-simple-roles.rb', line 15 def with_roles=(roles) self.roles = roles if roles.is_a? Array end |