Class: Openapi3Parser::NodeFactory::Map::ValidNodeBuilder

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ ValidNodeBuilder

Returns a new instance of ValidNodeBuilder.



112
113
114
115
# File 'lib/openapi3_parser/node_factory/map.rb', line 112

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

Class Method Details

.data(factory) ⇒ Object



108
109
110
# File 'lib/openapi3_parser/node_factory/map.rb', line 108

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

.errors(factory) ⇒ Object



104
105
106
# File 'lib/openapi3_parser/node_factory/map.rb', line 104

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

Instance Method Details

#dataObject



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/openapi3_parser/node_factory/map.rb', line 125

def data
  return default_value if factory.nil_input?

  TypeChecker.raise_on_invalid_type(factory.context, type: ::Hash)
  check_keys(raise_on_invalid: true)
  check_values(raise_on_invalid: true)
  validate(raise_on_invalid: true)

  factory.data.each_with_object({}) do |(key, value), memo|
    memo[key] = value.respond_to?(:node) ? value.node : value
  end
end

#errorsObject



117
118
119
120
121
122
123
# File 'lib/openapi3_parser/node_factory/map.rb', line 117

def errors
  return validatable.collection if factory.nil_input?
  TypeChecker.validate_type(validatable, type: ::Hash)
  return validatable.collection if validatable.errors.any?
  collate_errors
  validatable.collection
end