Sha256: 020545bcb99e1488492a76e8b515a8740ca755744f6ff9fcf59ef00e26bc16b1

Contents?: true

Size: 1014 Bytes

Versions: 3

Compression:

Stored size: 1014 Bytes

Contents

module Dry
  module Types
    extend Dry::Configurable

    setting :namespace, self

    class SchemaError < TypeError
      def initialize(key, value)
        super("#{value.inspect} (#{value.class}) has invalid type for :#{key}")
      end
    end

    SchemaKeyError = Class.new(KeyError)
    private_constant(:SchemaKeyError)

    class MissingKeyError < SchemaKeyError
      def initialize(key)
        super(":#{key} is missing in Hash input")
      end
    end

    class UnknownKeysError < SchemaKeyError
      def initialize(*keys)
        super("unexpected keys #{keys.inspect} in Hash input")
      end
    end

    ConstraintError = Class.new(TypeError) do
      attr_reader :result, :input

      def initialize(result, input)
        @result = result
        @input = input

        if result.is_a?(String)
          super(result)
        else
          super(to_s)
        end
      end

      def to_s
        "#{input.inspect} violates constraints (#{result} failed)"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-types-0.9.2 lib/dry/types/errors.rb
dry-types-0.9.1 lib/dry/types/errors.rb
dry-types-0.9.0 lib/dry/types/errors.rb