Module: Roles::ActiveRecord::Strategy::Shared
Instance Method Summary collapse
- #get_role ⇒ Object (also: #get_roles)
- #has_any_roles? ⇒ Boolean
- #has_no_roles? ⇒ Boolean
- #remove_all_roles! ⇒ Object
- #select_valid_roles(*roles) ⇒ Object
- #set_default_role ⇒ Object
- #set_role(role) ⇒ Object (also: #set_roles)
Instance Method Details
#get_role ⇒ Object Also known as: get_roles
26 27 28 |
# File 'lib/roles_active_record/strategy/shared.rb', line 26 def get_role r = self.send(role_attribute) end |
#has_any_roles? ⇒ Boolean
22 23 24 |
# File 'lib/roles_active_record/strategy/shared.rb', line 22 def has_any_roles? !has_no_roles? end |
#has_no_roles? ⇒ Boolean
18 19 20 |
# File 'lib/roles_active_record/strategy/shared.rb', line 18 def has_no_roles? get_role.empty? end |
#remove_all_roles! ⇒ Object
14 15 16 |
# File 'lib/roles_active_record/strategy/shared.rb', line 14 def remove_all_roles! set_empty_role end |
#select_valid_roles(*roles) ⇒ Object
31 32 33 34 |
# File 'lib/roles_active_record/strategy/shared.rb', line 31 def select_valid_roles *roles roles.flat_uniq.select{|role| valid_role? role } has_role_class? ? role_class.find_roles(roles).to_a.flat_uniq : roles.flat_uniq end |
#set_default_role ⇒ Object
5 6 7 |
# File 'lib/roles_active_record/strategy/shared.rb', line 5 def set_default_role add_role default_role end |
#set_role(role) ⇒ Object Also known as: set_roles
9 10 11 |
# File 'lib/roles_active_record/strategy/shared.rb', line 9 def set_role role update_attributes(role_attribute => new_role(role)) end |