Module: AuthAssistant::RoleStrategy::RolesMask

Defined in:
lib/auth_assistant/role_strategies/roles_mask.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
# File 'lib/auth_assistant/role_strategies/roles_mask.rb', line 25

def self.included(base)  
  base.extend(ClassMethods)
end

Instance Method Details

#role?(role) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/auth_assistant/role_strategies/roles_mask.rb', line 13

def role?(role)
  roles.include? role.to_s
end

#rolesObject



9
10
11
# File 'lib/auth_assistant/role_strategies/roles_mask.rb', line 9

def roles
  ROLES.reject { |r| ((roles_mask || 0) & calc_index(r)).zero? }
end

#roles=(*roles) ⇒ Object



5
6
7
# File 'lib/auth_assistant/role_strategies/roles_mask.rb', line 5

def roles=(*roles)        
  self.roles_mask = (roles & available_roles).map { |r| calc_index(r) }.sum
end