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

Instance Method Summary collapse

Constructor Details

#initializeRoleRegistry

Returns a new instance of RoleRegistry.



26
27
28
# File 'lib/hyrax/role_registry.rb', line 26

def initialize
  @roles = MAGIC_ROLES.dup
end

Instance Method Details

#add(name:, description:) ⇒ Object



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

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

#persist_registered_roles!Object

Load the registered roles into Sipity::Role



45
46
47
48
49
50
51
52
# File 'lib/hyrax/role_registry.rb', line 45

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)


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

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

#role_namesObject



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

def role_names
  @roles.keys.sort
end