Class: CSVStepImporter::Model::DAO

Inherits:
Node
  • Object
show all
Defined in:
lib/csv_step_importer/model/dao.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #env, #parent

Instance Method Summary collapse

Methods inherited from Node

#add_children, #validate_children

Methods inherited from Base

#assign_attributes, #inspect, #persisted?, #save, #save!, #to_s, #update

Constructor Details

#initialize(row:, **attributes) ⇒ DAO

Returns a new instance of DAO.



12
13
14
15
16
# File 'lib/csv_step_importer/model/dao.rb', line 12

def initialize(row:, **attributes)
  super **attributes

  self.row = row
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/csv_step_importer/model/dao.rb', line 6

def id
  @id
end

#rowObject

Returns the value of attribute row.



6
7
8
# File 'lib/csv_step_importer/model/dao.rb', line 6

def row
  @row
end

Instance Method Details

#create_or_updateObject



28
29
30
31
# File 'lib/csv_step_importer/model/dao.rb', line 28

def create_or_update
  # Daoの保存処理は基本的にstepsで行います
  true
end

#created_atObject



37
38
39
# File 'lib/csv_step_importer/model/dao.rb', line 37

def created_at
  current_timestamp
end

#current_timestampObject



33
34
35
# File 'lib/csv_step_importer/model/dao.rb', line 33

def current_timestamp
  model.cache[:updated_at] ||= (::ActiveRecord::Base.default_timezone == :utc ? ::Time.now.utc : ::Time.now).to_s(:db)
end

#modelObject



18
19
20
# File 'lib/csv_step_importer/model/dao.rb', line 18

def model
  parent.parent
end

#updated_atObject



41
42
43
# File 'lib/csv_step_importer/model/dao.rb', line 41

def updated_at
  current_timestamp
end

#valueObject



22
23
24
25
26
# File 'lib/csv_step_importer/model/dao.rb', line 22

def value
  @value ||= columns.each_with_object({}) do |key, values|
    values[key] = send key
  end
end