class Hyrax::Ingest::Ingester::ActiveFedoraPropertyAssigner

Attributes

af_model[R]
fetcher[R]
rdf_predicate[R]
transformer[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_property_assigner.rb, line 21
def initialize(options={})
  @rdf_predicate = options[:rdf_predicate]
  @fetcher = options[:fetcher]
  @af_model = options[:af_model]
  @transformer = options[:transformer]
  raise Hyrax::Ingest::Errors::UnknownActiveFedoraModel.new(@af_model.class) unless @af_model.is_a? ActiveFedora::Base
  raise Hyrax::Ingest::Errors::InvalidFetcher.new(@fetcher.class) unless @fetcher.is_a? Hyrax::Ingest::Fetcher::Base
end

Public Instance Methods

assign!() click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_property_assigner.rb, line 30
def assign!
  af_model.set_value(property_name, fetched_and_transformed_value)
rescue ::ActiveTriples::Relation::ValueError => e
  # Rethrow ActiveTriples::Relation::ValueError as something more specific to ingest.
  raise Hyrax::Ingest::Errors::InvalidActiveFedoraPropertyValue.new(fetched_value, property_name, rdf_predicate)
end

Private Instance Methods

fetched_and_transformed_value() click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_property_assigner.rb, line 39
def fetched_and_transformed_value
  @fetched_and_transformed_value ||= if transformer
    transformer.transform(fetched_value)
  else
    fetched_value
  end
end
fetched_value() click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_property_assigner.rb, line 47
def fetched_value
  @fetched_value ||= fetcher.fetch
end
property_name() click to toggle source

Performs a lookup of property name by RDF predicate. @return [Symbol] The symbol representing the accessor for the

property that matches the RDF predicate stored in the
@rdf_predicate attribtue.
# File lib/hyrax/ingest/ingester/active_fedora_property_assigner.rb, line 55
def property_name
  @property ||= begin
    property = af_model.send(:properties).select do |_att, config|
      config.predicate == rdf_predicate
    end
    raise Hyrax::Ingest::Errors::UnknownRdfPredicate.new(rdf_predicate, af_model.class) if property.keys.count == 0
    property.keys.first.to_sym
  end
end