Class: Dynamoid::Transactions::Mutation::Import
- Inherits:
-
Base
- Object
- Base
- Dynamoid::Transactions::Mutation::Import
show all
- Defined in:
- lib/dynamoid/transactions/mutation/import.rb
Instance Method Summary
collapse
Methods inherited from Base
validate_attribute_names!
Constructor Details
#initialize(model_class, array_of_attributes) ⇒ Import
Returns a new instance of Import.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 10
def initialize(model_class, array_of_attributes)
super()
@model_class = model_class
@models = array_of_attributes.map do |attributes|
attributes = attributes.symbolize_keys
if @model_class.timestamps_enabled?
time_now = DateTime.now.in_time_zone(Time.zone)
attributes[:created_at] ||= time_now
attributes[:updated_at] ||= time_now
end
model = @model_class.build(attributes)
model.hash_key = SecureRandom.uuid if model.hash_key.nil?
model
end
end
|
Instance Method Details
#aborted? ⇒ Boolean
49
50
51
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 49
def aborted?
false
end
|
#action_requests ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 61
def action_requests
@models.map do |model|
attributes_dumped = Dynamoid::Dumping.dump_attributes(model.attributes, @model_class.attributes)
attributes_dumped = sanitize_item(attributes_dumped)
{
put: {
item: attributes_dumped,
table_name: @model_class.table_name
}
}
end
end
|
#observable_by_user_result ⇒ Object
57
58
59
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 57
def observable_by_user_result
@models
end
|
#on_commit ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 35
def on_commit
@models.each do |model|
model.clear_changes_information
model.new_record = false
model.run_callbacks(:commit)
end
end
|
#on_registration ⇒ Object
29
30
31
32
33
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 29
def on_registration
@models.each do |model|
validate_primary_key!(model)
end
end
|
#on_rollback ⇒ Object
43
44
45
46
47
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 43
def on_rollback
@models.each do |model|
model.run_callbacks(:rollback)
end
end
|
#skipped? ⇒ Boolean
53
54
55
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 53
def skipped?
@models.empty?
end
|