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.



13
14
15
16
17
# File 'lib/openapi3_parser/validation/validatable.rb', line 13

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/openapi3_parser/validation/validatable.rb', line 9

def context
  @context
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/openapi3_parser/validation/validatable.rb', line 9

def errors
  @errors
end

#factoryObject (readonly)

Returns the value of attribute factory.



9
10
11
# File 'lib/openapi3_parser/validation/validatable.rb', line 9

def factory
  @factory
end

Instance Method Details

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/openapi3_parser/validation/validatable.rb', line 23

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



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

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

#collectionObject



39
40
41
# File 'lib/openapi3_parser/validation/validatable.rb', line 39

def collection
  ErrorCollection.new(errors)
end

#inputObject



19
20
21
# File 'lib/openapi3_parser/validation/validatable.rb', line 19

def input
  context.input
end