Sha256: f65c1f26ca08b4d1a5e61614b59997892de066826503542d82f6c0278608454a

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module Dry
  module Types
    extend Dry::Configurable

    # @!attribute [r] namespace
    #   @return [Container{String => Definition}]
    setting :namespace, self

    class SchemaError < TypeError
      # @param [String,Symbol] key
      # @param [Object] value
      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
      # @param [String,Symbol] key
      def initialize(key)
        super(":#{key} is missing in Hash input")
      end
    end

    class UnknownKeysError < SchemaKeyError
      # @param [<String, Symbol>] keys
      def initialize(*keys)
        super("unexpected keys #{keys.inspect} in Hash input")
      end
    end

    class ConstraintError < TypeError
      # @return [String, #to_s]
      attr_reader :result
      # @return [Object]
      attr_reader :input

      # @param [String, #to_s] result
      # @param [Object] input
      def initialize(result, input)
        @result = result
        @input = input

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

      # @return [String]
      def to_s
        "#{input.inspect} violates constraints (#{result} failed)"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-types-0.10.3 lib/dry/types/errors.rb
dry-types-0.10.2 lib/dry/types/errors.rb
dry-types-0.10.1 lib/dry/types/errors.rb
dry-types-0.10.0 lib/dry/types/errors.rb