Sha256: 6b57d77358f0708c4563c3cd50bdb8a2ad9640dd6a61be55514ab063c99157ee

Contents?: true

Size: 948 Bytes

Versions: 11

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Openapi3Parser
  module Validation
    class Validatable
      attr_reader :context, :errors, :factory

      UNDEFINED = Class.new

      def initialize(factory, context: nil)
        @factory = factory
        @context = context || factory.context
        @errors = []
      end

      def input
        context.input
      end

      def add_error(error, given_context = nil, factory_class = UNDEFINED)
        return unless error
        return @errors << error if error.is_a?(Validation::Error)

        @errors << Validation::Error.new(
          error,
          given_context || context,
          factory_class == UNDEFINED ? factory.class : factory_class
        )
      end

      def add_errors(errors)
        errors = errors.to_a if errors.respond_to?(:to_a)
        errors.each { |e| add_error(e) }
      end

      def collection
        ErrorCollection.new(errors)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
openapi3_parser-0.9.2 lib/openapi3_parser/validation/validatable.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/openapi3_parser-0.9.1/lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.9.1 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.9.0 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.8.2 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.8.1 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.8.0 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.7.0 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.6.1 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.6.0 lib/openapi3_parser/validation/validatable.rb
openapi3_parser-0.5.2 lib/openapi3_parser/validation/validatable.rb