Class: Openapi3Parser::Validation::Validatable

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/validation/validatable.rb

Constant Summary collapse

UNDEFINED =
Class.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory, context: nil) ⇒ Validatable

Returns a new instance of Validatable.



10
11
12
13
14
# File 'lib/openapi3_parser/validation/validatable.rb', line 10

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/openapi3_parser/validation/validatable.rb', line 6

def context
  @context
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/openapi3_parser/validation/validatable.rb', line 6

def errors
  @errors
end

#factoryObject (readonly)

Returns the value of attribute factory.



6
7
8
# File 'lib/openapi3_parser/validation/validatable.rb', line 6

def factory
  @factory
end

Instance Method Details

#add_error(error, given_context = nil, factory_class = UNDEFINED) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/openapi3_parser/validation/validatable.rb', line 20

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

#add_errors(errors) ⇒ Object



31
32
33
34
# File 'lib/openapi3_parser/validation/validatable.rb', line 31

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

#collectionObject



36
37
38
# File 'lib/openapi3_parser/validation/validatable.rb', line 36

def collection
  ErrorCollection.new(errors)
end

#inputObject



16
17
18
# File 'lib/openapi3_parser/validation/validatable.rb', line 16

def input
  context.input
end