Class: Openapi3Parser::Node::Placeholder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_factory, field, parent_context) ⇒ Placeholder

Returns a new instance of Placeholder.


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

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

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field


34
35
36
# File 'lib/openapi3_parser/node/placeholder.rb', line 34

def field
  @field
end

#node_factoryObject (readonly)

Returns the value of attribute node_factory


34
35
36
# File 'lib/openapi3_parser/node/placeholder.rb', line 34

def node_factory
  @node_factory
end

#parent_contextObject (readonly)

Returns the value of attribute parent_context


34
35
36
# File 'lib/openapi3_parser/node/placeholder.rb', line 34

def 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 before iteration


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/openapi3_parser/node/placeholder.rb', line 21

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

  resolved.each(&block)
end

.resolve(potential_placeholder) ⇒ Object


10
11
12
13
14
15
16
# File 'lib/openapi3_parser/node/placeholder.rb', line 10

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

Instance Method Details

#nodeObject


44
45
46
47
48
49
50
51
# File 'lib/openapi3_parser/node/placeholder.rb', line 44

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