Sha256: 97bf77ea38e3e30f6a16508511d3abc9c48bbcf9c0c9af664542dbd17931d590

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

module StateFu

  class Exception < ::Exception
    attr_reader :binding, :options
  end

  class RequirementError < Exception
    attr_reader :transition
    DEFAULT_MESSAGE = "The transition was halted"

    def initialize( transition, message=DEFAULT_MESSAGE, options={})
      @transition = transition
      @options    = options
      super( message )
    end

    def inspect
      "<StateFu::RequirementError #{message} #{@transition.origin.name}=[#{@transition.event.name}]=>#{transition.target.name}"
    end
  end

  class TransitionHalted < Exception
    attr_reader :transition

    DEFAULT_MESSAGE = "The transition was halted"

    def initialize( transition, message=DEFAULT_MESSAGE, options={})
      @transition = transition
      @options    = options
      super( message )
    end
  end

  class InvalidTransition < Exception
    attr_reader :binding, :origin, :target, :event, :args

    DEFAULT_MESSAGE = "An invalid transition was attempted"

    def initialize( binding,
                    event,
                    origin,
                    target,
                    message=DEFAULT_MESSAGE,
                    options={})
      @binding = binding
      @event   = event
      @origin  = origin
      @target  = target
      @options = options
      super( message )
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
davidlee-state-fu-0.2.0 lib/state_fu/exceptions.rb