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.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 11
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)
if model.hash_key.nil? && hash_key_string?
model.hash_key = SecureRandom.uuid
end
model
end
end
|
Instance Method Details
#aborted? ⇒ Boolean
52
53
54
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 52
def aborted?
false
end
|
#action_requests ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 64
def action_requests
@models.map do |model|
attributes_dumped = Dynamoid::Dumping.dump_attributes(model.attributes, @model_class.attributes)
attributes_dumped = sanitize_item(attributes_dumped)
Builders::PutRequestBuilder.new(@model_class, attributes_dumped).request
end
end
|
#observable_by_user_result ⇒ Object
60
61
62
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 60
def observable_by_user_result
@models
end
|
#on_commit ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 38
def on_commit
@models.each do |model|
model.clear_changes_information
model.new_record = false
model.run_callbacks(:commit)
end
end
|
#on_registration ⇒ Object
32
33
34
35
36
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 32
def on_registration
@models.each do |model|
validate_primary_key!(model)
end
end
|
#on_rollback ⇒ Object
46
47
48
49
50
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 46
def on_rollback
@models.each do |model|
model.run_callbacks(:rollback)
end
end
|
#skipped? ⇒ Boolean
56
57
58
|
# File 'lib/dynamoid/transactions/mutation/import.rb', line 56
def skipped?
@models.empty?
end
|