Class: Dynamoid::Transactions::Mutation::Destroy
- Inherits:
-
Base
- Object
- Base
- Dynamoid::Transactions::Mutation::Destroy
show all
- Defined in:
- lib/dynamoid/transactions/mutation/destroy.rb
Instance Method Summary
collapse
Methods inherited from Base
validate_attribute_names!
Constructor Details
#initialize(model, **options) ⇒ Destroy
Returns a new instance of Destroy.
11
12
13
14
15
16
17
18
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 11
def initialize(model, **options)
super()
@model = model
@options = options
@model_class = model.class
@aborted = false
end
|
Instance Method Details
#aborted? ⇒ Boolean
45
46
47
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 45
def aborted?
@aborted
end
|
#action_requests ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 59
def action_requests
builder = Builders::DeleteRequestBuilder.new(@model_class)
builder.hash_key = dump_attribute(@model_class.hash_key, @model.hash_key)
builder.range_key = dump_attribute(@model_class.range_key, @model.range_value) if @model_class.range_key?
if @model_class.attributes[:lock_version]
lock_version = if @model.changes[:lock_version].nil?
@model.lock_version
else
@model.changes[:lock_version][0]
end
if lock_version
builder.add_expression_attribute_name('#_lock_version', 'lock_version')
builder.add_expression_attribute_value(':lock_version_value', lock_version)
builder.condition_expression = '#_lock_version = :lock_version_value'
end
end
[builder.request]
end
|
#observable_by_user_result ⇒ Object
53
54
55
56
57
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 53
def observable_by_user_result
return false if @aborted
@model
end
|
#on_commit ⇒ Object
34
35
36
37
38
39
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 34
def on_commit
return if @aborted
@model.destroyed = true
@model.run_callbacks(:commit)
end
|
#on_registration ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 20
def on_registration
@aborted = true
@model.run_callbacks(:destroy) do
validate_primary_key!
@aborted = false
true
end
if @aborted && @options[:raise_error]
raise Dynamoid::Errors::RecordNotDestroyed, @model
end
end
|
#on_rollback ⇒ Object
41
42
43
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 41
def on_rollback
@model.run_callbacks(:rollback)
end
|
#skipped? ⇒ Boolean
49
50
51
|
# File 'lib/dynamoid/transactions/mutation/destroy.rb', line 49
def skipped?
false
end
|