class CSVStepImporter::Model::DAO

Attributes

attributes[RW]
id[RW]
row[RW]

Public Class Methods

new(parent:, row:, **attributes) click to toggle source

Logic

Calls superclass method CSVStepImporter::Node::new
# File lib/csv_step_importer/model/dao.rb, line 24
def initialize(parent:, row:, **attributes)
  super parent: parent

  self.attributes = attributes
  self.row = row
end

Public Instance Methods

create_or_update() click to toggle source
# File lib/csv_step_importer/model/dao.rb, line 57
def create_or_update
  # DAOs are usually processed in batches by the model and not saved one by one
  true
end
current_timestamp() click to toggle source
# File lib/csv_step_importer/model/dao.rb, line 62
def current_timestamp
  model.cache[:updated_at] ||= (::ActiveRecord::Base.default_timezone == :utc ? ::Time.now.utc : ::Time.now).to_s(:db)
end
model() click to toggle source
# File lib/csv_step_importer/model/dao.rb, line 31
def model
  parent.parent
end
value() click to toggle source

returns an array of all column values, used for batch importing

# File lib/csv_step_importer/model/dao.rb, line 36
def value
  @value ||= values_for columns
end
value_for_key(key) click to toggle source

retrieve a value for a key from the dao or row

# File lib/csv_step_importer/model/dao.rb, line 41
def value_for_key(key)
  if respond_to?(key)
    send key
  elsif attributes.include? key
    attributes[key]
  else
    row.send key
  end
end
values_for(included_keys) click to toggle source
# File lib/csv_step_importer/model/dao.rb, line 51
def values_for(included_keys)
  included_keys.each_with_object({}) do |key, values|
    values[key] = value_for_key key
  end
end