Module: RoleStrategy::Mongoid::RoleString::Implementation
- Includes:
- Mongoid::Roles::Strategy::Single
- Defined in:
- lib/roles_mongoid/strategy/single/role_string.rb
Instance Method Summary collapse
- #new_role(role) ⇒ Object
- #new_roles(*roles) ⇒ Object
- #present_role(role) ⇒ Object (also: #present_roles)
- #set_empty_role ⇒ Object
Instance Method Details
#new_role(role) ⇒ Object
35 36 37 38 |
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 35 def new_role role role = role.kind_of?(Array) ? role.first : role role.to_s end |
#new_roles(*roles) ⇒ Object
40 41 42 |
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 40 def new_roles *roles new_role roles.flatten.first end |
#present_role(role) ⇒ Object Also known as: present_roles
44 45 46 47 |
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 44 def present_role role return role if role.kind_of? Array role.split(',').map(&:to_sym) end |
#set_empty_role ⇒ Object
49 50 51 |
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 49 def set_empty_role self.send("#{role_attribute}=", "") end |