Class: Arrthorizer::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/arrthorizer/role.rb

Direct Known Subclasses

ContextRole, Group

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(name_or_role) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/arrthorizer/role.rb', line 10

def self.get(name_or_role)
  if name_or_role.respond_to?(:instance)
    get(name_or_role.instance)
  else
    registry.fetch(name_or_role)
  end
end

.register(role) ⇒ Object



18
19
20
# File 'lib/arrthorizer/role.rb', line 18

def self.register(role)
  registry.add(role)
end

.registryObject



22
23
24
# File 'lib/arrthorizer/role.rb', line 22

def self.registry
  @registry ||= Registry.new
end

Instance Method Details

#applies_to_user?(user, context = {}) ⇒ Boolean

Template method: This method is implemented in the ContextRole subclasses and Group.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/arrthorizer/role.rb', line 6

def applies_to_user?(user, context = {})
  raise NotImplementedError, "#{self.name} does not implement #applies_to_user?(user, context)"
end

#to_keyObject



26
27
28
# File 'lib/arrthorizer/role.rb', line 26

def to_key
  name
end