class Hyrax::Ingest::Fetcher::Base
Public Class Methods
# File lib/hyrax/ingest/fetcher/base.rb, line 28 def initialize(options={}) @required = options.delete(:required) end
Public Instance Methods
Subclasses should override this method with the logic required to fetch values from a SIP
. The overidden method should set @fetched_value, and return it. @see Hyrax::Ingest::Fetcher::XMLFile#fetch
@abstract
# File lib/hyrax/ingest/fetcher/base.rb, line 40 def fetch @fetched_value end
Boolean reader for @required.
# File lib/hyrax/ingest/fetcher/base.rb, line 33 def required?; !!@required; end
Protected Instance Methods
Determines whether the value that was fetched by fetch
is empty or not. Be default, the fetched value is empty if it is nil, an empty string, an empty array, an empty hash, or an array containing any combination of those. Overwrite this method in subclasses to change the definition of empty in those contexts. The return value is used for reporting which values are missing, but required. @return [Boolean] True if @fetched_value is considered to be empty; false otherwise.
# File lib/hyrax/ingest/fetcher/base.rb, line 54 def fetched_value_is_empty? Array(@fetched_value).reduce(true) do |all_empty, val| all_empty &&= ( val.nil? || ( val.respond_to?(:empty?) && val.empty? ) ) end end
Reports occurrences of missing required values. Subclasses should override this method to provide further detail by passing an options hash that will be available for reporting. @see Hyrax::Ingest::Fetcher::XMLFile#report_missing_required_value
@example
# Provide additional info to the report. def report_missing_require_value super(foo: "bar") end
# File lib/hyrax/ingest/fetcher/base.rb, line 69 def report_missing_required_value(params={}) short_class_name = self.class.to_s.gsub(/.*\:\:/, '') logger.warn "Missing required value from #{short_class_name} with params = #{params}" report.stat[:missing_required_values][self.class] ||= [] report.stat[:missing_required_values][self.class] << params end