Class: Hyrax::Identifier::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/identifier/dispatcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registrar:) ⇒ Dispatcher

Returns a new instance of Dispatcher.

Parameters:


12
13
14
# File 'app/services/hyrax/identifier/dispatcher.rb', line 12

def initialize(registrar:)
  @registrar = registrar
end

Instance Attribute Details

#registrarHyrax::Identifier::Registrar


8
9
10
# File 'app/services/hyrax/identifier/dispatcher.rb', line 8

def registrar
  @registrar
end

Class Method Details

.for(type, **registrar_opts) ⇒ Hyrax::Identifier::Dispatcher

Returns a dispatcher with an registrar for the given type.

Parameters:

  • type (Symbol)
  • registrar_opts (Hash)

Options Hash (**registrar_opts):

Returns:

See Also:

  • IdentifierRegistrar.for

25
26
27
# File 'app/services/hyrax/identifier/dispatcher.rb', line 25

def for(type, **registrar_opts)
  new(registrar: Hyrax::Identifier::Registrar.for(type, **registrar_opts))
end

Instance Method Details

#assign_for(object:, attribute: :identifier) ⇒ ActiveFedora::Base, Hyrax::Resource

Note:

the attribute for identifier storage must be multi-valued, and will be overwritten during assignment.

Assigns an identifier to the object.

This involves two steps:

- Registering the identifier with the registrar service via `registrar`.
- Storing the new identifier on the object, in the provided `attribute`.

Parameters:

  • attribute (Symbol) (defaults to: :identifier)

    the attribute in which to store the identifier. This attribute will be overwritten during assignment.

  • object (ActiveFedora::Base, Hyrax::Resource)

    the object to assign an identifier.

Returns:

  • (ActiveFedora::Base, Hyrax::Resource)

    object


45
46
47
48
49
# File 'app/services/hyrax/identifier/dispatcher.rb', line 45

def assign_for(object:, attribute: :identifier)
  record = registrar.register!(object: object)
  object.public_send("#{attribute}=".to_sym, [record.identifier])
  object
end

#assign_for!(object:, attribute: :identifier) ⇒ Object

Assigns an identifier and saves the object.

See Also:


55
56
57
58
# File 'app/services/hyrax/identifier/dispatcher.rb', line 55

def assign_for!(object:, attribute: :identifier)
  assign_for(object: object, attribute: attribute).save!
  object
end