Class: CSVStepImporter::Model::DAO
- Inherits:
-
Node
- Object
- Base
- Node
- CSVStepImporter::Model::DAO
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, #run_validations!, #validate_children
Methods inherited from Base
#assign_attributes, #inspect, #persisted?, #save, #save!, #to_s, #update
Constructor Details
#initialize(parent:, row:, **attributes) ⇒ DAO
Returns a new instance of DAO.
12
13
14
15
16
17
|
# File 'lib/csv_step_importer/model/dao.rb', line 12
def initialize(parent:, row:, **attributes)
super parent: parent
self.attributes = attributes
self.row = row
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6
7
8
|
# File 'lib/csv_step_importer/model/dao.rb', line 6
def attributes
@attributes
end
|
#id ⇒ Object
Returns the value of attribute id.
6
7
8
|
# File 'lib/csv_step_importer/model/dao.rb', line 6
def id
@id
end
|
#row ⇒ Object
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_update ⇒ Object
43
44
45
46
|
# File 'lib/csv_step_importer/model/dao.rb', line 43
def create_or_update
true
end
|
#created_at ⇒ Object
52
53
54
|
# File 'lib/csv_step_importer/model/dao.rb', line 52
def created_at
current_timestamp
end
|
#current_timestamp ⇒ Object
48
49
50
|
# File 'lib/csv_step_importer/model/dao.rb', line 48
def current_timestamp
model.cache[:updated_at] ||= (::ActiveRecord::Base.default_timezone == :utc ? ::Time.now.utc : ::Time.now).to_s(:db)
end
|
#model ⇒ Object
19
20
21
|
# File 'lib/csv_step_importer/model/dao.rb', line 19
def model
parent.parent
end
|
#updated_at ⇒ Object
56
57
58
|
# File 'lib/csv_step_importer/model/dao.rb', line 56
def updated_at
current_timestamp
end
|
#value ⇒ Object
23
24
25
26
27
|
# File 'lib/csv_step_importer/model/dao.rb', line 23
def value
@value ||= columns.each_with_object({}) do |key, values|
values[key] = value_for_key key
end
end
|
#value_for_key(key) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/csv_step_importer/model/dao.rb', line 29
def value_for_key(key)
if respond_to?(key)
send key
elsif attributes.include? key
attributes[key]
elsif row.respond_to?(key)
row.send key
elsif row.attributes.include? key
row.attributes[key]
else
nil
end
end
|