Class: Openapi3Parser::Node::Placeholder

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/node/placeholder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_factory, field, parent_context) ⇒ Placeholder

Returns a new instance of Placeholder.



30
31
32
33
34
# File 'lib/openapi3_parser/node/placeholder.rb', line 30

def initialize(node_factory, field, parent_context)
  @node_factory = node_factory
  @field = field
  @parent_context = parent_context
end

Class Method Details

.each(node_data, &block) ⇒ Object

Used to iterate through hashes or arrays that may contain Placeholder objects where these are resolved to being nodes befor iteration



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/openapi3_parser/node/placeholder.rb', line 17

def self.each(node_data, &block)
  resolved =
    if node_data.respond_to?(:keys)
      node_data.each_with_object({}) do |(key, value), memo|
        memo[key] = resolve(value)
      end
    else
      node_data.map { |item| resolve(item) }
    end

  resolved.each(&block)
end

.resolve(potential_placeholder) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/openapi3_parser/node/placeholder.rb', line 6

def self.resolve(potential_placeholder)
  if potential_placeholder.is_a?(Placeholder)
    potential_placeholder.node
  else
    potential_placeholder
  end
end

Instance Method Details

#nodeObject



36
37
38
39
40
41
42
43
# File 'lib/openapi3_parser/node/placeholder.rb', line 36

def node
  @node ||= begin
              node_context = Context.next_field(parent_context,
                                                field,
                                                node_factory.context)
              node_factory.node(node_context)
            end
end