class Contracto::SystemActionChain

Public Class Methods

new(*actions) click to toggle source
# File lib/contracto/system_action.rb, line 54
def initialize(*actions)
  @actions = actions
  @finished_actions = []
end

Public Instance Methods

execute() click to toggle source
# File lib/contracto/system_action.rb, line 59
def execute
  perform_actions and true
rescue StandardError => e
  revert_actions and false
  raise e
end

Private Instance Methods

perform_actions() click to toggle source
# File lib/contracto/system_action.rb, line 68
def perform_actions
  @actions.each do |action|
    @finished_actions << action
    Contracto::SystemAction.send(action)
  end
end
revert_actions() click to toggle source
# File lib/contracto/system_action.rb, line 75
def revert_actions
  @finished_actions.reverse.each do |action|
    revert_method_name = "revert_#{action}"
    if Contracto::SystemAction.respond_to? revert_method_name
      Contracto::SystemAction.send revert_method_name
    end
  end
rescue StandardError
end