Class: Smuggle::Importer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/smuggle/importer/base.rb

Direct Known Subclasses

ApplicationImporter

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, model) ⇒ Base

Returns a new instance of Base.



28
29
30
31
# File 'lib/smuggle/importer/base.rb', line 28

def initialize(row, model)
  @model = model
  @row = row
end

Class Attribute Details

.attributes(*names) ⇒ Object



13
14
15
# File 'lib/smuggle/importer/base.rb', line 13

def attributes(*names)
  @attributes.concat names
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



26
27
28
# File 'lib/smuggle/importer/base.rb', line 26

def model
  @model
end

#rowObject (readonly)

Returns the value of attribute row.



26
27
28
# File 'lib/smuggle/importer/base.rb', line 26

def row
  @row
end

Class Method Details

.attributes?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/smuggle/importer/base.rb', line 17

def attributes?
  @attributes.any?
end

.csv_convertersObject



21
22
23
# File 'lib/smuggle/importer/base.rb', line 21

def csv_converters
  Hash(header_converters: :symbol, converters: %i[all])
end

.inherited(subclass) ⇒ Object



9
10
11
# File 'lib/smuggle/importer/base.rb', line 9

def inherited(subclass)
  subclass.attributes = []
end

Instance Method Details

#persistObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/smuggle/importer/base.rb', line 33

def persist
  raise NotImplementedError
end

#to_hObject



37
38
39
40
41
# 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