Module: Bulkrax::FactoryClassFinder::ValkyrieMigrationCoercer

Defined in:
app/services/bulkrax/factory_class_finder.rb

Overview

A name coercer that favors classes that end with “Resource” but will attempt to fallback to those that don’t.

Constant Summary collapse

SUFFIX =
"Resource"

Class Method Summary collapse

Class Method Details

.call(name, suffix: SUFFIX) ⇒ Class

Returns when the name is a coercible constant.

Parameters:

  • name (String)
  • suffix (String) (defaults to: SUFFIX)

    the suffix we use for a naming convention.

Returns:

  • (Class)

    when the name is a coercible constant.

Raises:

  • (NameError)

    when the name is not coercible to a constant.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/bulkrax/factory_class_finder.rb', line 29

def self.call(name, suffix: SUFFIX)
  if name.end_with?(suffix)
    name.constantize
  elsif name == "FileSet"
    Bulkrax.file_model_class
  else
    begin
      "#{name}#{suffix}".constantize
    rescue NameError
      name.constantize
    end
  end
end