Module: RoleStrategy::Mongoid::RolesMask::Implementation

Defined in:
lib/roles_mongoid/strategy/multi/roles_mask.rb

Defined Under Namespace

Classes: Roles

Instance Method Summary collapse

Instance Method Details

#role_attributeObject



52
53
54
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 52

def role_attribute
  strategy_class.roles_attribute_name
end

#rolesObject

query assigned roles



63
64
65
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 63

def roles
  strategy_class::Roles.new(self, strategy_class.valid_roles.reject { |r| ((self.send(role_attribute) || 0) & calc_index(r)).zero? })
end

#roles=(*roles) ⇒ Object Also known as: role=

assign roles



57
58
59
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 57

def roles=(*roles)
  self.send("#{role_attribute}=", (roles.flatten.map { |r| r.to_sym } & strategy_class.valid_roles).map { |r| calc_index(r) }.inject { |sum, bitvalue| sum + bitvalue })
end

#roles_listObject



67
68
69
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 67

def roles_list
  roles.to_a
end