Class: Hyrax::RoleRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/role_registry.rb

Overview

Responsible for registering roles critical for your application. Registering a role is effectively saying “my application logic will not work if this role goes away”.

See Also:

Constant Summary collapse

MANAGING =

You may develop your application assuming that the ‘managing’ role will always be present and valid

'managing'
APPROVING =

You may develop your application assuming that the ‘approving’ role will always be present and valid

'approving'
DEPOSITING =

You may develop your application assuming that the ‘depositing’ role will always be present and valid

'depositing'
MAGIC_ROLES =

It is a safe assumption that Hyrax has these magic roles. While the descriptions may be mutable, the names are assumed to exist.

{
  MANAGING => 'Grants access to management tasks',
  APPROVING => 'Grants access to approval tasks',
  DEPOSITING => 'Grants access to depositing tasks'
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeRoleRegistry

Returns a new instance of RoleRegistry.



32
33
34
# File 'lib/hyrax/role_registry.rb', line 32

def initialize
  @roles = MAGIC_ROLES.dup
end

Instance Method Details

#add(name:, description:) ⇒ Object



36
37
38
# File 'lib/hyrax/role_registry.rb', line 36

def add(name:, description:)
  @roles[name.to_s] = description
end

#persist_registered_roles!Object

Load the registered roles into Sipity::Role



51
52
53
54
55
56
57
58
# File 'lib/hyrax/role_registry.rb', line 51

def persist_registered_roles!
  @roles.each do |name, description|
    Sipity::Role.find_or_create_by!(name: name).tap do |role|
      role.description = description
      role.save!
    end
  end
end

#registered_role?(name:) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/hyrax/role_registry.rb', line 44

def registered_role?(name:)
  @roles.key?(name.to_s)
end

#role_namesObject



40
41
42
# File 'lib/hyrax/role_registry.rb', line 40

def role_names
  @roles.keys.sort
end