Class: Bulkrax::FactoryClassFinder
- Inherits:
-
Object
- Object
- Bulkrax::FactoryClassFinder
- Defined in:
- app/services/bulkrax/factory_class_finder.rb
Defined Under Namespace
Modules: DefaultCoercer, ValkyrieMigrationCoercer
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
Class Method Summary collapse
Instance Method Summary collapse
- #find ⇒ Class, Nil
-
#initialize(entry:, coercer:) ⇒ FactoryClassFinder
constructor
A new instance of FactoryClassFinder.
- #name ⇒ String private
Constructor Details
#initialize(entry:, coercer:) ⇒ FactoryClassFinder
Returns a new instance of FactoryClassFinder.
51 52 53 54 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 51 def initialize(entry:, coercer:) @entry = entry @coercer = coercer end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
55 56 57 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 55 def coercer @coercer end |
#entry ⇒ Object (readonly)
Returns the value of attribute entry.
55 56 57 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 55 def entry @entry end |
Class Method Details
.find(entry:, coercer: Bulkrax.factory_class_name_coercer || DefaultCoercer) ⇒ Class
47 48 49 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 47 def self.find(entry:, coercer: Bulkrax.factory_class_name_coercer || DefaultCoercer) new(entry: entry, coercer: coercer).find end |
Instance Method Details
#find ⇒ Class, Nil
61 62 63 64 65 66 67 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 61 def find coercer.call(name) rescue NameError nil rescue entry.default_work_type.constantize end |
#name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/services/bulkrax/factory_class_finder.rb', line 72 def name fc = if entry.&.[]('model').present? Array.wrap(entry.['model']).first elsif entry.importerexporter&.mapping&.[]('work_type').present? # Because of delegation's nil guard, we're reaching rather far into the implementation # details. Array.wrap(entry.['work_type']).first else entry.default_work_type end # Let's coerce this into the right shape; we're not mutating the string because it might well # be frozen. fc = fc.tr(' ', '_') fc = fc.downcase if fc.match?(/[-_]/) fc.camelcase rescue entry.default_work_type end |