Module: RoleStrategy::ActiveRecord::RolesMask::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#calc_index(r) ⇒ Object



38
39
40
# File 'lib/roles_active_record/strategy/multi/roles_mask.rb', line 38

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

#in_any_role(*roles) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/roles_active_record/strategy/multi/roles_mask.rb', line 27

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

#in_role(role) ⇒ Object



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

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

#role_attributeObject



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

def role_attribute
  strategy_class.roles_attribute_name.to_sym
end