Sha256: b88e1862b72e35a6114678b603e00fa4a7c88d51246df20875041190e15e5d12

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Statesman
  class InvalidStateError < StandardError; end
  class InvalidTransitionError < StandardError; end
  class InvalidCallbackError < StandardError; end

  class TransitionFailedError < StandardError
    def initialize(from, to)
      @from = from
      @to = to
    end

    attr_reader :from, :to

    def message
      "Cannot transition from '#{from}' to '#{to}'"
    end
  end

  class GuardFailedError < StandardError
    def initialize(from, to)
      @from = from
      @to = to
    end

    attr_reader :from, :to

    def message
      "Guard on transition from: '#{from}' to '#{to}' returned false"
    end
  end

  class TransitionConflictError < StandardError; end
  class MissingTransitionAssociation < StandardError; end

  class UnserializedMetadataError < StandardError
    def initialize(transition_class_name)
      super(_message(transition_class_name))
    end

    private

    def _message(transition_class_name)
      "#{transition_class_name}#metadata is not serialized. If you " \
      "are using a non-json column type, you should `include " \
      "Statesman::Adapters::ActiveRecordTransition`"
    end
  end

  class IncompatibleSerializationError < StandardError
    def initialize(transition_class_name)
      super(_message(transition_class_name))
    end

    private

    def _message(transition_class_name)
      "#{transition_class_name}#metadata column type cannot be json " \
      "and serialized simultaneously. If you are using a json " \
      "column type, it is not necessary to `include " \
      "Statesman::Adapters::ActiveRecordTransition`"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statesman-7.0.1 lib/statesman/exceptions.rb
statesman-7.0.0 lib/statesman/exceptions.rb
statesman-6.0.0 lib/statesman/exceptions.rb