module Actions::Storage

Public Class Methods

new(context = {}) click to toggle source
Calls superclass method
# File lib/actions/action/storage.rb, line 4
def initialize(context = {})
  super
rescue Actions::Errors::ValidationFailed => error
  context = JSON.load(JSON.dump(error.context.to_h))
  store(:validation_failed, context, { message: context.message })
end

Public Instance Methods

call() click to toggle source
Calls superclass method
# File lib/actions/action/storage.rb, line 11
def call
  store_around(:started, :done, :failed) do
    super
  end
end
rollback() click to toggle source
Calls superclass method
# File lib/actions/action/storage.rb, line 17
def rollback
  store_around(:rollback_started, :rollback_succeeded, :rollback_failed) do
    super
  end
end

Private Instance Methods

store(status, input, output) click to toggle source
# File lib/actions/action/storage.rb, line 25
def store(status, input, output)
  Actions.storage_adapter.store(
    name: self.class.name,
    context_id: self.context.id,
    input: input,
    output: output,
    status: status
  )
end
store_around(initial, success, failure, &block) click to toggle source
# File lib/actions/action/storage.rb, line 35
def store_around(initial, success, failure, &block)
  input_context = JSON.load(JSON.dump(context.to_h))
  begin
    store(initial, input_context, nil)
    block.call
    store(success, input_context, context.to_h)
  rescue
    store(failure, input_context, context.to_h)
    raise
  end
end