Class: Hyrax::Identifier::Dispatcher
- Inherits:
-
Object
- Object
- Hyrax::Identifier::Dispatcher
- Defined in:
- app/services/hyrax/identifier/dispatcher.rb
Instance Attribute Summary collapse
Class Method Summary collapse
-
.for(type, **registrar_opts) ⇒ Hyrax::Identifier::Dispatcher
A dispatcher with an registrar for the given type.
Instance Method Summary collapse
-
#assign_for(object:, attribute: :identifier) ⇒ ActiveFedora::Base, Hyrax::Resource
Assigns an identifier to the object.
-
#assign_for!(object:, attribute: :identifier) ⇒ Object
Assigns an identifier and saves the object.
-
#initialize(registrar:) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(registrar:) ⇒ Dispatcher
Returns a new instance of Dispatcher.
12 13 14 |
# File 'app/services/hyrax/identifier/dispatcher.rb', line 12 def initialize(registrar:) @registrar = registrar end |
Instance Attribute Details
#registrar ⇒ Hyrax::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.
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`.
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, Array.wrap(record.identifier)) object end |
#assign_for!(object:, attribute: :identifier) ⇒ Object
Assigns an identifier and saves the object.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/hyrax/identifier/dispatcher.rb', line 55 def assign_for!(object:, attribute: :identifier) result = assign_for(object: object, attribute: attribute) case result when Valkyrie::Resource Hyrax.persister.save(resource: result) else result.save result end end |