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
link!()
click to toggle source
link this dao to a row
# File lib/csv_step_importer/model/dao.rb, line 67 def link! # add to cache with pluralized key (row.cache[model.cache_key(pluralize: true)] ||= []) << self # add to cache with singular key (for convenience) row.cache[model.cache_key(pluralize: false)] = self end
model()
click to toggle source
# File lib/csv_step_importer/model/dao.rb, line 31 def model parent.parent end
unlink!(replace_with: nil)
click to toggle source
unlink this dao from the row and replace it with a different dao
# File lib/csv_step_importer/model/dao.rb, line 76 def unlink!(replace_with: nil) cached_daos = row.cache[model.cache_key(pluralize: true)] # remove from cache with pluralized key cached_daos.delete self cached_daos << replace_with # set any dao to cache with singular key (for convenience) row.cache[model.cache_key(pluralize: false)] = cached_daos.first 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