Module: RoleStrategy::Mongoid::RolesMask::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#calc_index(r) ⇒ Object



32
33
34
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 32

def calc_index(r)
  2**strategy_class.valid_roles.index(r.to_sym)
end

#in_role(role) ⇒ Object



16
17
18
19
20
21
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 16

def in_role(role)     
  mask = calc_index(role.to_s)
  all.select do |user| 
    (user.send(role_attribute) & mask) > 0
  end
end

#in_roles(*roles) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 23

def in_roles(*roles)
  all.select do |user| 
    roles.flatten.any? do |role|
      mask = calc_index(role.to_s)
      (user.send(role_attribute) & mask) > 0
    end
  end
end

#role_attributeObject



12
13
14
# File 'lib/roles_mongoid/strategy/multi/roles_mask.rb', line 12

def role_attribute
  strategy_class.roles_attribute_name.to_sym
end