Module: CsvRowModel::Import::Base

Extended by:
ActiveSupport::Concern
Includes:
CsvRowModel::Inspect
Included in:
CsvRowModel::Import
Defined in:
lib/csv_row_model/concerns/import/base.rb

Constant Summary collapse

INSPECT_METHODS =
%i[source_attributes initialized_at parent context previous].freeze

Instance Method Summary collapse

Methods included from CsvRowModel::Inspect

#inspect

Instance Method Details

#abort?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if the entire csv file should stop reading


50
51
52
# File 'lib/csv_row_model/concerns/import/base.rb', line 50

def abort?
  false
end

#free_previousObject

Free previous from memory to avoid making a linked list


35
36
37
38
# File 'lib/csv_row_model/concerns/import/base.rb', line 35

def free_previous
  attributes
  @previous = nil
end

#initialize(source_row_or_exception = [], options = {}) ⇒ Object

Parameters:

  • source_row_or_exception (Array) (defaults to: [])

    the csv row

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :index (Integer)

    1st row_model is 0, 2nd is 1, 3rd is 2, etc.

  • :line_number (Integer)

    line_number in the CSV file

  • :source_headers (Array)

    the csv header row

  • :previous (CsvRowModel::Import)

    the previous row model

  • :parent (CsvRowModel::Import)

    if the instance is a child, pass the parent


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/csv_row_model/concerns/import/base.rb', line 22

def initialize(source_row_or_exception=[], options={})
  @source_row = source_row_or_exception
  @csv_exception = source_row if source_row.kind_of? Exception
  @source_row = [] if source_row_or_exception.class != Array

  @line_number, @index, @source_headers = options[:line_number], options[:index], options[:source_headers]

  @previous = options[:previous].try(:dup)
  previous.try(:free_previous)
  super(options)
end

#skip?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if this instance should be skipped


43
44
45
# File 'lib/csv_row_model/concerns/import/base.rb', line 43

def skip?
  !valid?
end