Module: RoleStrategy::Mongoid::RoleString::Implementation

Defined in:
lib/roles_mongoid/strategy/single/role_string.rb

Instance Method Summary collapse

Instance Method Details

#role=(role_name) ⇒ Object



32
33
34
35
36
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 32

def role= role_name
  if role_name.kind_of_label? && valid_role?(role_name)
    self.send("#{role_attribute}=", role_name.to_s) 
  end        
end

#role_attributeObject



23
24
25
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 23

def role_attribute
  strategy_class.roles_attribute_name
end

#rolesObject Also known as: roles_list

query assigned roles



39
40
41
42
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 39

def roles
  role = self.send(role_attribute)
  [role.to_sym]
end

#roles=(*roles) ⇒ Object

assign roles



28
29
30
# File 'lib/roles_mongoid/strategy/single/role_string.rb', line 28

def roles=(*roles)
  self.role = roles.select_labels.first.to_s
end