Class: Wings::ActiveFedoraConverter::InstanceBuilder
- Inherits:
-
Object
- Object
- Wings::ActiveFedoraConverter::InstanceBuilder
- Defined in:
- lib/wings/active_fedora_converter/instance_builder.rb
Overview
Constructs an instance for the given converter. converter
must provide an id
, resource
, and active_fedora_class
.
This interface allows handling for special cases based on the target class, instance data for resource
, or the id format. This originated as an extraction of some such special handling from the converter code.
Instance Attribute Summary collapse
- #converter ⇒ #active_fedora_class, ... readonly
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #build ⇒ ActiveFedora::Common
- #builds_file_metadata? ⇒ Boolean
- #builds_metadata_for_active_fedora_file? ⇒ Boolean
-
#initialize(converter) ⇒ InstanceBuilder
constructor
A new instance of InstanceBuilder.
Constructor Details
#initialize(converter) ⇒ InstanceBuilder
Returns a new instance of InstanceBuilder.
22 23 24 25 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 22 def initialize(converter) @converter = converter @resource = converter.resource end |
Instance Attribute Details
#converter ⇒ #active_fedora_class, ... (readonly)
18 19 20 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 18 def converter @converter end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
18 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 18 attr_reader :converter, :resource |
Instance Method Details
#build ⇒ ActiveFedora::Common
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 29 def build if && ! # convert to a generic/generated FileMetadataNode class with # properties matching the source class Wings::ActiveFedoraConverter::FileMetadataNode(resource.class) .new(file_identifier: Array(resource.file_identifier) .map(&:to_s)) elsif converter.id.present? converter.active_fedora_class.find(converter.id) else converter.active_fedora_class.new end rescue ActiveFedora::ObjectNotFoundError converter.active_fedora_class.new end |
#builds_file_metadata? ⇒ Boolean
47 48 49 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 47 def resource.try(:file_identifier).present? end |
#builds_metadata_for_active_fedora_file? ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 53 def return false unless adapter_for_file = begin ::Valkyrie::StorageAdapter.adapter_for(id: resource.file_identifier) rescue ::Valkyrie::StorageAdapter::AdapterNotFoundError => err Hyrax.logger.warn "Processing a FileMetadata (id: #{converter.id}) referencing " \ "a file #{resource.file_identifier}; could not find a " \ "storage adapter to handle that file.\n\t#{err.}" end adapter_for_file.is_a?(::Valkyrie::Storage::Fedora) end |