Module: Hyrax::Ingest::Fetcher

Defined in:
lib/hyrax/ingest/fetcher.rb,
lib/hyrax/ingest/fetcher/base.rb,
lib/hyrax/ingest/fetcher/literal.rb,
lib/hyrax/ingest/fetcher/rdf_uri.rb,
lib/hyrax/ingest/fetcher/csv_file.rb,
lib/hyrax/ingest/fetcher/xml_file.rb,
lib/hyrax/ingest/fetcher/date_time.rb,
lib/hyrax/ingest/fetcher/yaml_file.rb,
lib/hyrax/ingest/fetcher/premis_event_type.rb

Defined Under Namespace

Classes: Base, CSVFile, DateTime, Literal, PremisEventType, RdfUri, XMLFile, YAMLFile

Class Method Summary collapse

Class Method Details

.all_classesObject

Returns Set The set of all fetcher classes.

Returns:

  • Set The set of all fetcher classes.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hyrax/ingest/fetcher.rb', line 15

def all_classes
  @all_classes ||= Set.new.tap do |all_classes|
    all_classes << Hyrax::Ingest::Fetcher::XMLFile
    all_classes << Hyrax::Ingest::Fetcher::YAMLFile
    all_classes << Hyrax::Ingest::Fetcher::CSVFile
    all_classes << Hyrax::Ingest::Fetcher::Literal
    all_classes << Hyrax::Ingest::Fetcher::PremisEventType
    all_classes << Hyrax::Ingest::Fetcher::RdfUri
    all_classes << Hyrax::Ingest::Fetcher::DateTime
  end
end

.factory(class_name, options = {}) ⇒ Object

Returns An instance of the fetcher class.

Parameters:

  • options (string) (defaults to: {})

    The key is the fetcher class name and the value is the hash of options to pass to the constructor of the fetcher class.

Returns:

  • An instance of the fetcher class.



31
32
33
34
# File 'lib/hyrax/ingest/fetcher.rb', line 31

def factory(class_name, options={})
  options ||= {}
  find_class_by_name(class_name).new(options)
end

.find_class_by_name(class_name) ⇒ Class

Returns The appropriate fetcher class.

Parameters:

  • class_name (String)

    The stringified class name, with our without namespaces.

Returns:

  • (Class)

    The appropriate fetcher class.

Raises:

  • (Hyrax::Ingest::Errors::UnknownFetcherClass)

    When there is no corresponding fetcher class for the given value of the ‘class_name` param.

  • (Hyrax::Ingest::Errors::UnknownfetcherClass)

    When the value of ‘class_name` param is insufficient in determining a fetcher class.



44
45
46
47
48
49
50
51
# File 'lib/hyrax/ingest/fetcher.rb', line 44

def find_class_by_name(class_name)
  found_classes = all_classes.select do |class_const|
    (class_const.to_s == class_name) || (class_const.to_s =~ /::#{class_name}/)
  end
  raise Hyrax::Ingest::Errors::UnknownFetcherClass.new(class_name, all_classes) if found_classes.count == 0
  raise Hyrax::Ingest::Errors::AmbiguousFetcherClass.new(class_name, found_classes) if found_classes.count > 1
  found_classes.first
end