Class: Wings::ActiveFedoraConverter::InstanceBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(converter) ⇒ InstanceBuilder

Returns a new instance of InstanceBuilder.

Parameters:



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)

Returns:



18
19
20
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 18

def converter
  @converter
end

#resourceObject (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

#buildActiveFedora::Common

Returns:

  • (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 builds_file_metadata? && !
    # 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

Returns:

  • (Boolean)


47
48
49
# File 'lib/wings/active_fedora_converter/instance_builder.rb', line 47

def builds_file_metadata?
  resource.try(:file_identifier).present?
end

#builds_metadata_for_active_fedora_file?Boolean

Returns:

  • (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 builds_file_metadata?

  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.message}"
                     end

  adapter_for_file.is_a?(::Valkyrie::Storage::Fedora)
end