Class: Dynamoid::TransactionWrite::Destroy

Inherits:
Base
  • Object
show all
Defined in:
lib/dynamoid/transaction_write/destroy.rb

Instance Method Summary collapse

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, **options)
  super()

  @model = model
  @options = options
  @model_class = model.class
  @aborted = false
end

Instance Method Details

#aborted?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dynamoid/transaction_write/destroy.rb', line 42

def aborted?
  @aborted
end

#action_requestObject



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_resultObject



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_commitObject



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_registrationObject



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_rollbackObject



38
39
40
# File 'lib/dynamoid/transaction_write/destroy.rb', line 38

def on_rollback
  @model.run_callbacks(:rollback)
end

#skipped?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dynamoid/transaction_write/destroy.rb', line 46

def skipped?
  false
end