Module: RoleStrategy::Mongoid::OneRole::Implementation
- Includes:
- Mongoid::Roles::Strategy::Single
- Defined in:
- lib/roles_mongoid/strategy/single/one_role.rb
Instance Method Summary collapse
- #new_role(role) ⇒ Object
- #new_roles(*roles) ⇒ Object
- #present_roles(*roles) ⇒ Object
- #select_valid_roles(*role_names) ⇒ Object
- #set_empty_role ⇒ Object
Instance Method Details
#new_role(role) ⇒ Object
41 42 43 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 41 def new_role role role_class.find_role(extract_role role) end |
#new_roles(*roles) ⇒ Object
45 46 47 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 45 def new_roles *roles new_role roles.flatten.first end |
#present_roles(*roles) ⇒ Object
49 50 51 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 49 def present_roles *roles roles.map{|role| extract_role role} end |
#select_valid_roles(*role_names) ⇒ Object
57 58 59 60 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 57 def select_valid_roles *role_names role_names = role_names.flat_uniq.select{|role| valid_role? role } has_role_class? ? role_class.find_roles(role_names).to_a : role_names end |
#set_empty_role ⇒ Object
53 54 55 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 53 def set_empty_role self.send("#{role_attribute}=", nil) end |