Module: Bulkrax::CsvEntry::AttributeBuilderMethod

Defined in:
app/models/bulkrax/csv_entry.rb

Overview

The purpose of this helper module is to make easier the testing of the rather complex switching logic for determining the method we use for building the value.

Class Method Summary collapse

Class Method Details

.for(key:, value:, entry:) ⇒ NilClass, Symbol

Parameters:

Returns:

  • (NilClass)

    when we won’t be processing this field

  • (Symbol)

    (either :build_value or :build_object)



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'app/models/bulkrax/csv_entry.rb', line 210

def self.for(key:, value:, entry:)
  return if key == 'model'
  return if key == 'file'
  return if key == entry.related_parents_parsed_mapping
  return if key == entry.related_children_parsed_mapping
  return if value['excluded'] || value[:excluded]
  return if Bulkrax.reserved_properties.include?(key) && !entry.field_supported?(key)

  object_key = key if value.key?('object') || value.key?(:object)
  return unless entry.hyrax_record.respond_to?(key.to_s) || object_key.present?

  models_to_skip = Array.wrap(value['skip_object_for_model_names'] || value[:skip_object_for_model_names] || [])

  return :build_value if models_to_skip.detect { |model| entry.factory_class.model_name.name == model }
  return :build_object if object_key.present?

  :build_value
end