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.



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

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

Class Method Details

.data(factory, parent_context) ⇒ Object



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

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

.errors(factory) ⇒ Object



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

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

Instance Method Details

#data(parent_context) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/openapi3_parser/node_factory/map.rb', line 126

def data(parent_context)
  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] = if value.respond_to?(:node)
                  Node::Placeholder.new(value, key, parent_context)
                else
                  value
                end
  end
end

#errorsObject



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

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