Sha256: ab04cd7ea06b93b44a738c11852983e66079739f8f717c156cef552780a5fb0f
Contents?: true
Size: 1.97 KB
Versions: 9
Compression:
Stored size: 1.97 KB
Contents
# frozen_string_literal: true module Hyrax module Identifier class Dispatcher ## # @!attribute [rw] registrar # @return [Hyrax::Identifier::Registrar] attr_accessor :registrar ## # @param registrar [Hyrax::Identifier::Registrar] def initialize(registrar:) @registrar = registrar end class << self ## # @param type [Symbol] # @param registrar_opts [Hash] # @option registrar_opts [Hyrax::Identifier::Builder] :builder # # @return [Hyrax::Identifier::Dispatcher] a dispatcher with an registrar for the # given type # @see IdentifierRegistrar.for def for(type, **registrar_opts) new(registrar: Hyrax::Identifier::Registrar.for(type, **registrar_opts)) end end ## # 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`. # # @note the attribute for identifier storage must be multi-valued, and will # be overwritten during assignment. # # @param attribute [Symbol] the attribute in which to store the identifier. # This attribute will be overwritten during assignment. # @param object [ActiveFedora::Base, Hyrax::Resource] the object to assign an identifier. # # @return [ActiveFedora::Base, Hyrax::Resource] object def assign_for(object:, attribute: :identifier) record = registrar.register!(object: object) object.public_send("#{attribute}=".to_sym, [record.identifier]) object end ## # Assigns an identifier and saves the object. # # @see #assign_for def assign_for!(object:, attribute: :identifier) assign_for(object: object, attribute: attribute).save! object end end end end
Version data entries
9 entries across 9 versions & 1 rubygems