class Openapi3Parser::NodeFactory::Map

Attributes

allow_extensions[R]
context[R]
data[R]
default[R]
validation[R]
value_factory[R]
value_input_type[R]

Public Class Methods

new( context, allow_extensions: false, default: {}, value_input_type: nil, value_factory: nil, validate: nil ) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/openapi3_parser/node_factory/map.rb, line 11
def initialize(
  context,
  allow_extensions: false,
  default: {},
  value_input_type: nil,
  value_factory: nil,
  validate: nil
)
  @context = context
  @allow_extensions = allow_extensions
  @default = default
  @value_input_type = value_input_type
  @value_factory = value_factory
  @validation = validate
  @data = build_data(context.input)
end

Public Instance Methods

errors() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 45
def errors
  @errors ||= ValidNodeBuilder.errors(self)
end
inspect() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 54
def inspect
  %{#{self.class.name}(#{context.source_location.inspect})}
end
nil_input?() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 37
def nil_input?
  context.input.nil?
end
node(node_context) click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 49
def node(node_context)
  data = ValidNodeBuilder.data(self, node_context)
  data.nil? ? nil : build_node(data, node_context)
end
raw_input() click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/openapi3_parser/node_factory/map.rb, line 29
def raw_input
  context.input
end
resolved_input() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 33
def resolved_input
  @resolved_input ||= build_resolved_input
end
valid?() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 41
def valid?
  errors.empty?
end

Private Instance Methods

build_data(raw_input) click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 60
def build_data(raw_input)
  use_default = nil_input? || !raw_input.is_a?(::Hash)
  return if use_default && default.nil?

  process_data(use_default ? default : raw_input)
end
build_node(data, node_context) click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 86
def build_node(data, node_context)
  Node::Map.new(data, node_context) if data
end
build_resolved_input() click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 90
def build_resolved_input
  return unless data

  data.transform_values do |value|
    if value.respond_to?(:resolved_input)
      value.resolved_input
    else
      value
    end
  end
end
initialize_value_factory(field_context) click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 78
def initialize_value_factory(field_context)
  if value_factory.is_a?(Class)
    value_factory.new(field_context)
  else
    value_factory.call(field_context)
  end
end
process_data(data) click to toggle source
# File lib/openapi3_parser/node_factory/map.rb, line 67
def process_data(data)
  data.each_with_object({}) do |(key, value), memo|
    memo[key] = if EXTENSION_REGEX =~ key.to_s || !value_factory
                  value
                else
                  next_context = Context.next_field(context, key)
                  initialize_value_factory(next_context)
                end
  end
end