Class: Openapi3Parser::Node::Map

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

Direct Known Subclasses

Callback, Paths, Responses, SecurityRequirement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, context) ⇒ Map

Returns a new instance of Map.



14
15
16
17
# File 'lib/openapi3_parser/node/map.rb', line 14

def initialize(data, context)
  @node_data = data
  @node_context = context
end

Instance Attribute Details

#node_contextObject (readonly)

Returns the value of attribute node_context.



12
13
14
# File 'lib/openapi3_parser/node/map.rb', line 12

def node_context
  @node_context
end

#node_dataObject (readonly)

Returns the value of attribute node_data.



12
13
14
# File 'lib/openapi3_parser/node/map.rb', line 12

def node_data
  @node_data
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Any)

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/openapi3_parser/node/map.rb', line 54

def ==(other)
  other.instance_of?(self.class) &&
    node_context.same_data_and_source?(other.node_context)
end

#[](value) ⇒ Object

Look up an attribute of the node by the name it has in the OpenAPI document.

Examples:

Look up by OpenAPI naming

obj["externalDocs"]

Look up by symbol

obj[:servers]

Look up an extension

obj["x-myExtension"]

Parameters:

  • value (String, Symbol)

Returns:

  • anything



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

def [](value)
  Placeholder.resolve(node_data[value.to_s])
end

#each(&block) ⇒ Object

Iterates through the data of this node, used by Enumerable

Returns:



62
63
64
# File 'lib/openapi3_parser/node/map.rb', line 62

def each(&block)
  Placeholder.each(node_data, &block)
end

#extension(value) ⇒ Hash, ...

Look up an extension provided for this map, doesn’t need a prefix of “x-”

Examples:

Looking up an extension provided as “x-extra”

obj.extension("extra")

Parameters:

  • value (String, Symbol)

Returns:

  • (Hash, Array, Numeric, String, true, false, nil)


47
48
49
# File 'lib/openapi3_parser/node/map.rb', line 47

def extension(value)
  self["x-#{value}"]
end

#inspectString

Returns:

  • (String)


83
84
85
86
# File 'lib/openapi3_parser/node/map.rb', line 83

def inspect
  fragment = node_context.document_location.pointer.fragment
  %{#{self.class.name}(#{fragment})}
end

#node_at(pointer_like) ⇒ Object

Used to access a node relative to this node

Parameters:

Returns:

  • anything



77
78
79
80
# File 'lib/openapi3_parser/node/map.rb', line 77

def node_at(pointer_like)
  current_pointer = node_context.document_location.pointer
  node_context.document.node_at(pointer_like, current_pointer)
end

#valuesArray

Provide an array of values for this object, a partner to the #keys method

Returns:



70
71
72
# File 'lib/openapi3_parser/node/map.rb', line 70

def values
  map(&:last)
end