Class: Dynamoid::TransactionWrite::UpdateFields
- Inherits:
-
Base
- Object
- Base
- Dynamoid::TransactionWrite::UpdateFields
show all
- Defined in:
- lib/dynamoid/transaction_write/update_fields.rb
Defined Under Namespace
Classes: UpdateRequestBuilder
Instance Method Summary
collapse
Constructor Details
#initialize(model_class, hash_key, range_key, attributes, &block) ⇒ UpdateFields
Returns a new instance of UpdateFields.
9
10
11
12
13
14
15
16
17
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 9
def initialize(model_class, hash_key, range_key, attributes, &block)
super()
@model_class = model_class
@hash_key = hash_key
@range_key = range_key
@attributes = attributes || {}
@block = block
end
|
Instance Method Details
#aborted? ⇒ Boolean
33
34
35
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 33
def aborted?
false
end
|
#action_request ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 45
def action_request
builder = UpdateRequestBuilder.new(@model_class)
builder.hash_key = dump_attribute(@model_class.hash_key, @hash_key)
builder.range_key = dump_attribute(@model_class.range_key, @range_key) if @model_class.range_key?
changes = @attributes.dup
changes = add_timestamps(changes, skip_created_at: true)
changes_dumped = Dynamoid::Dumping.dump_attributes(changes, @model_class.attributes)
builder.set_attributes(changes_dumped)
if @item_updater
builder.set_attributes(@item_updater.attributes_to_set)
builder.remove_attributes(@item_updater.attributes_to_remove)
@item_updater.attributes_to_add.each do |name, value|
if @model_class.attributes[name][:type] == :set
value = value.is_a?(Enumerable) ? Set.new(value) : Set[value]
end
builder.add_value(name, value)
end
@item_updater.attributes_to_delete.each do |name, value|
value = value.is_a?(Enumerable) ? Set.new(value) : Set[value]
builder.delete_value(name, value)
end
end
condition_expression = "attribute_exists(#{@model_class.hash_key})"
if @model_class.range_key?
condition_expression += " AND attribute_exists(#{@model_class.range_key})"
end
builder.condition_expression = condition_expression
builder.request
end
|
#observable_by_user_result ⇒ Object
41
42
43
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 41
def observable_by_user_result
nil
end
|
#on_commit ⇒ Object
29
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 29
def on_commit; end
|
#on_registration ⇒ Object
#on_rollback ⇒ Object
31
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 31
def on_rollback; end
|
#skipped? ⇒ Boolean
37
38
39
|
# File 'lib/dynamoid/transaction_write/update_fields.rb', line 37
def skipped?
@attributes.empty? && (!@item_updater || @item_updater.empty?)
end
|