Module: RoleStrategy::MongoMapper::RolesMask::ClassMethods
- Defined in:
- lib/roles_mongo_mapper/strategy/multi/roles_mask.rb
Instance Method Summary collapse
- #calc_index(r) ⇒ Object
- #in_any_role(*roles) ⇒ Object
- #in_role(role) ⇒ Object
- #role_attribute ⇒ Object
Instance Method Details
#calc_index(r) ⇒ Object
34 35 36 |
# File 'lib/roles_mongo_mapper/strategy/multi/roles_mask.rb', line 34 def calc_index(r) 2**strategy_class.valid_roles.index(r.to_sym) end |
#in_any_role(*roles) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/roles_mongo_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) (user.send(role_attribute) & mask) > 0 end end end |
#in_role(role) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/roles_mongo_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_attribute ⇒ Object
14 15 16 |
# File 'lib/roles_mongo_mapper/strategy/multi/roles_mask.rb', line 14 def role_attribute strategy_class.roles_attribute_name.to_sym end |