Class: Openapi3Parser::Node::Placeholder
- Inherits:
-
Object
- Object
- Openapi3Parser::Node::Placeholder
- Extended by:
- Forwardable
- Defined in:
- lib/openapi3_parser/node/placeholder.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#node_factory ⇒ Object
readonly
Returns the value of attribute node_factory.
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
Class Method Summary collapse
-
.each(node_data) ⇒ Object
Used to iterate through hashes or arrays that may contain Placeholder objects where these are resolved to being nodes before iteration.
- .resolve(potential_placeholder) ⇒ Object
Instance Method Summary collapse
-
#initialize(node_factory, field, parent_context) ⇒ Placeholder
constructor
A new instance of Placeholder.
- #node ⇒ Object
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
#field ⇒ Object (readonly)
Returns the value of attribute field.
34 35 36 |
# File 'lib/openapi3_parser/node/placeholder.rb', line 34 def field @field end |
#node_factory ⇒ Object (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_context ⇒ Object (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) ⇒ 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, &) 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(&) 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
#node ⇒ Object
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 |