Sha256: a10e340eaff5c1877d6e673f29e3ab1035174fd9982b72fb1c389900d33dae1f

Contents?: true

Size: 1.93 KB

Versions: 9

Compression:

Stored size: 1.93 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; class All
# Set: All cards (Abort)
#
module Abort;
extend Card::Set
def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/abort.rb"; end

# The Card#abort method is for cleanly exiting an action without continuing
# to process any further events.
#
# Three statuses are supported:
#
#   failure: adds an error, returns false on save
#   success: no error, returns true on save
#   triumph: similar to success, but if called on a subcard
#            it causes the entire action to abort (not just the subcard)
def abort status, msg="action canceled"
  director.abort
  if status == :failure && errors.empty?
    errors.add :abort, msg
  elsif status.is_a?(Hash) && status[:success]
    success << status[:success]
    status = :success
  end
  raise Card::Error::Abort.new(status, msg)
end

def aborting
  yield
  errors.any? ? abort(:failure) : abort(:success)
end

def abortable
  yield
rescue Card::Error::Abort => e
  handle_abort_error e
end

private

def handle_abort_error e
  if e.status == :triumph
    @supercard ? raise(e) : true
  elsif e.status == :success
    abort_success
  end
end

def abort_success
  if @supercard
    @supercard.subcards.delete key
    @supercard.director.subdirectors.delete self
    expire :soft
  end
  true
end

# this is an override of standard rails behavior that rescues abort
# makes it so that :success abortions do not rollback
def with_transaction_returning_status
  status = nil
  self.class.transaction do
    add_to_transaction
    status = abortable { yield }
    raise ActiveRecord::Rollback unless status
  end
  status
end

# FIXME: these two do not belong here!

public

event :notable_exception_raised do
  error = Card::Error.current
  Rails.logger.debug "#{error.message}\n#{error.backtrace * "\n  "}"
end

def success
  Env.success(name)
end
end;end;end;end;
# ~~ generated from /Users/ethan/dev/decko/gem/card/mod/core/set/all/abort.rb ~~

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-1.99.4 tmpsets/set/mod003-core/all/abort.rb
card-1.99.3 tmpsets/set/mod003-core/all/abort.rb
card-1.99.2 tmpsets/set/mod003-core/all/abort.rb
card-1.99.1 tmpsets/set/mod003-core/all/abort.rb
card-1.99.0 tmpsets/set/mod003-core/all/abort.rb
card-1.98.3 tmpsets/set/mod003-core/all/abort.rb
card-1.98.2 tmpsets/set/mod003-core/all/abort.rb
card-1.98.1 tmpsets/set/mod003-core/all/abort.rb
card-1.98.0 tmpsets/set/mod003-core/all/abort.rb