Class: Openapi3Parser::NodeFactory::ObjectFactory::NodeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/node_factory/object_factory/node_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ NodeBuilder

Returns a new instance of NodeBuilder.



15
16
17
18
# File 'lib/openapi3_parser/node_factory/object_factory/node_builder.rb', line 15

def initialize(factory)
  @factory = factory
  @validatable = Validation::Validatable.new(factory)
end

Class Method Details

.errors(factory) ⇒ Object



7
8
9
# File 'lib/openapi3_parser/node_factory/object_factory/node_builder.rb', line 7

def self.errors(factory)
  new(factory).errors
end

.node_data(factory, node_context) ⇒ Object



11
12
13
# File 'lib/openapi3_parser/node_factory/object_factory/node_builder.rb', line 11

def self.node_data(factory, node_context)
  new(factory).node_data(node_context)
end

Instance Method Details

#errorsObject



20
21
22
23
24
25
26
27
28
# File 'lib/openapi3_parser/node_factory/object_factory/node_builder.rb', line 20

def errors
  return validatable.collection if empty_and_allowed_to_be?

  TypeChecker.validate_type(validatable, type: ::Hash)

  validatable.add_errors(validate(raise_on_invalid: false)) if validatable.errors.empty?

  validatable.collection
end

#node_data(node_context) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/openapi3_parser/node_factory/object_factory/node_builder.rb', line 30

def node_data(node_context)
  return build_node_data(node_context) if empty_and_allowed_to_be?

  TypeChecker.raise_on_invalid_type(factory.context, type: ::Hash)
  validate(raise_on_invalid: true)
  build_node_data(node_context)
end