class Hyrax::Ingest::Ingester::ActiveFedoraBaseIngester
Attributes
af_model_class_name[R]
properties_config[R]
update_params[R]
Public Class Methods
new(config={})
click to toggle source
Calls superclass method
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 28 def initialize(config={}) raise ArgumentError, "Option :af_model_class_name is required" unless config.key?(:af_model_class_name) @af_model_class_name = config.delete(:af_model_class_name).to_s @properties_config = config.delete(:properties) || [] @update_params = config.delete(:update) super(config) end
Public Instance Methods
af_model()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 41 def af_model @af_model ||= new_or_existing_af_model end
run!()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 36 def run! assign_properties! save_model! end
Protected Instance Methods
assign_properties!()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 55 def assign_properties! property_assigners.each do |property_assigner| property_assigner.assign! end end
save_model!(continue_if_invalid: true)
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 47 def save_model!(continue_if_invalid: true) af_model.save! af_model rescue ActiveFedora::RecordInvalid => e raise e unless continue_if_invalid false end
Private Instance Methods
af_model_class()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 63 def af_model_class Object.const_get(af_model_class_name.to_s) rescue NameError => e raise Hyrax::Ingest::Errors::UnknownActiveFedoraModel.new(af_model_class_name) end
create_fetcher_from_config(fetcher_config)
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 111 def create_fetcher_from_config(fetcher_config) fetcher_class_name = fetcher_config.keys.first fetcher_class_options = fetcher_config.values.first Hyrax::Ingest::Fetcher.factory(fetcher_class_name, fetcher_class_options).tap do |fetcher| if fetcher.respond_to?(:sip=) fetcher.sip = if use_shared_sip?(fetcher_config[fetcher_class_name]) raise Hyrax::Ingest::Errors::NoSharedSIPSpecified unless shared_sip shared_sip else sip end end fetcher.iteration = iteration if fetcher.respond_to? :iteration= fetcher.logger = logger if fetcher.respond_to? :logger= fetcher.report = report if fetcher.respond_to? :report= end end
new_or_existing_af_model()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 69 def new_or_existing_af_model if where_clause af_model_class.where(where_clause).first.tap do |found_record| raise Hyrax::Ingest::Errors::RecordNotFound.new(af_model_class, where_clause) unless found_record end else af_model_class.new end end
property_assigners()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 93 def property_assigners @property_assigners ||= properties_config.map do |property_config| property_assigner_options = { rdf_predicate: property_config[:rdf_predicate], fetcher: create_fetcher_from_config(property_config[:from]), af_model: af_model } if property_config.key?(:transform) transformer_class_name = property_config[:transform].keys.first transformer_class_options = property_config[:transform].values.first property_assigner_options[:transformer] = Hyrax::Ingest::Transformer.factory(transformer_class_name, transformer_class_options) end ActiveFedoraPropertyAssigner.new(property_assigner_options) end end
where_clause()
click to toggle source
# File lib/hyrax/ingest/ingester/active_fedora_base_ingester.rb, line 79 def where_clause return unless update_params {}.tap do |where_clause| update_params.each do |field, from_params| where_clause[field] = begin value = create_fetcher_from_config(from_params[:from]).fetch # Cast to string unless value is an array value = value.to_s unless value.respond_to? :each value end end end end