Sha256: dbf9651b4a453567040f6d72456a7cad740141853def96e4b8c40b3beb521d64

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Avro
  module Builder

    class RequiredAttributeError < StandardError
      def initialize(type:, attribute:, field: nil, name: nil)
        location = if field
                     "field '#{field}' of "
                   elsif name
                     "'#{name}' of "
                   end
        super("attribute :#{attribute} missing for #{location}type :#{type}")
      end
    end

    class DuplicateDefinitionError < StandardError
      def initialize(key, object, existing_object)
        super("definition for #{key.inspect} already exists\n"\
              "existing definition:\n#{to_json(existing_object)}\n"\
              "new definition:\n#{to_json(object)})")
      end

      private

      def to_json(object)
        object.to_h(SchemaSerializerReferenceState.new).to_json
      end
    end

    class DefinitionNotFoundError < StandardError
      def initialize(name)
        super("definition not found for '#{name.to_s}'.#{suggest_namespace(name)}")
      end

      private

      def suggest_namespace(name)
        unless name.to_s.index('.')
          ' Try specifying the full namespace.'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
avro-builder-0.5.0 lib/avro/builder/errors.rb