class Smuggle::Importer::Base

Attributes

attributes[W]
model[R]
row[R]

Public Class Methods

attributes(*names) click to toggle source
# File lib/smuggle/importer/base.rb, line 13
def attributes(*names)
  @attributes.concat names
end
attributes?() click to toggle source
# File lib/smuggle/importer/base.rb, line 17
def attributes?
  @attributes.any?
end
csv_converters() click to toggle source
# File lib/smuggle/importer/base.rb, line 21
def csv_converters
  Hash(header_converters: :symbol, converters: %i[all])
end
inherited(subclass) click to toggle source
# File lib/smuggle/importer/base.rb, line 9
def inherited(subclass)
  subclass.attributes = []
end
new(row, model) click to toggle source
# File lib/smuggle/importer/base.rb, line 28
def initialize(row, model)
  @model = model
  @row = row
end

Public Instance Methods

persist() click to toggle source
# File lib/smuggle/importer/base.rb, line 33
def persist
  raise NotImplementedError
end
to_h() click to toggle source
# File lib/smuggle/importer/base.rb, line 37
def to_h
  defined_attributes.each_with_object({}) do |attribute, hash|
    hash[attribute.to_sym] = respond_to?(attribute) ? public_send(attribute) : row[attribute.to_sym]
  end
end

Private Instance Methods

defined_attributes() click to toggle source
# File lib/smuggle/importer/base.rb, line 45
def defined_attributes
  return self.class.attributes if self.class.attributes?

  return model.attribute_names if model.respond_to?(:attribute_names)

  []
end