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'.freeze
APPROVING =

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

'approving'.freeze
DEPOSITING =

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

'depositing'.freeze
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'.freeze,
  APPROVING => 'Grants access to approval tasks'.freeze,
  DEPOSITING => 'Grants access to depositing tasks'.freeze
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeRoleRegistry

Returns a new instance of RoleRegistry.



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

def initialize
  @roles = MAGIC_ROLES.dup
end

Instance Method Details

#add(name:, description:) ⇒ Object



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

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

#persist_registered_roles!Object

Load the registered roles into Sipity::Role



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

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)


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

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

#role_namesObject



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

def role_names
  @roles.keys.sort
end