Module: RoleStrategy::DataMapper::RolesMask::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#calc_index(r) ⇒ Object



36
37
38
39
40
# File 'lib/roles_data_mapper/strategy/multi/roles_mask.rb', line 36

def calc_index(r)
  idx = strategy_class.valid_roles.index(r.to_sym)
  return nil if !idx
  2**idx
end

#in_any_role(*roles) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/roles_data_mapper/strategy/multi/roles_mask.rb', line 25

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

#in_role(role) ⇒ Object



18
19
20
21
22
23
# File 'lib/roles_data_mapper/strategy/multi/roles_mask.rb', line 18

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

#role_attributeObject



14
15
16
# File 'lib/roles_data_mapper/strategy/multi/roles_mask.rb', line 14

def role_attribute
  strategy_class.roles_attribute_name.to_sym
end