Class: Dynamoid::TransactionWrite::Destroy
- Defined in:
- lib/dynamoid/transaction_write/destroy.rb
Instance Method Summary collapse
- #aborted? ⇒ Boolean
- #action_request ⇒ Object
-
#initialize(model, **options) ⇒ Destroy
constructor
A new instance of Destroy.
- #observable_by_user_result ⇒ Object
- #on_commit ⇒ Object
- #on_registration ⇒ Object
- #on_rollback ⇒ Object
- #skipped? ⇒ Boolean
Constructor Details
#initialize(model, **options) ⇒ Destroy
Returns a new instance of Destroy.
8 9 10 11 12 13 14 15 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 8 def initialize(model, **) super() @model = model @options = @model_class = model.class @aborted = false end |
Instance Method Details
#aborted? ⇒ Boolean
42 43 44 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 42 def aborted? @aborted end |
#action_request ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 56 def action_request key = { @model_class.hash_key => @model.hash_key } if @model_class.range_key? key[@model_class.range_key] = @model.range_value end { delete: { key: key, table_name: @model_class.table_name } } end |
#observable_by_user_result ⇒ Object
50 51 52 53 54 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 50 def observable_by_user_result return false if @aborted @model end |
#on_commit ⇒ Object
31 32 33 34 35 36 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 31 def on_commit return if @aborted @model.destroyed = true @model.run_callbacks(:commit) end |
#on_registration ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 17 def on_registration validate_model! @aborted = true @model.run_callbacks(:destroy) do @aborted = false true end if @aborted && @options[:raise_error] raise Dynamoid::Errors::RecordNotDestroyed, @model end end |
#on_rollback ⇒ Object
38 39 40 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 38 def on_rollback @model.run_callbacks(:rollback) end |
#skipped? ⇒ Boolean
46 47 48 |
# File 'lib/dynamoid/transaction_write/destroy.rb', line 46 def skipped? false end |