Class: Openapi3Parser::Node::Context
- Inherits:
-
Object
- Object
- Openapi3Parser::Node::Context
- Defined in:
- lib/openapi3_parser/node/context.rb
Overview
This class is used to specify the data and source information for a Node, for every node there is a different context to represent it’s place within the document.
Instance Attribute Summary collapse
-
#document_location ⇒ Source::Location
readonly
The location in the root source of this node.
-
#input ⇒ Any
readonly
The raw data that was used to build the node.
-
#source_location ⇒ Source::Location
readonly
The location in a source file of this.
Class Method Summary collapse
-
.next_field(parent_context, field, factory_context) ⇒ Node::Context
Create a context for the child of a previous context.
-
.resolved_reference(current_context, reference_factory_context) ⇒ Node::Context
Create a context for a the a field that is the result of a reference.
-
.root(factory_context) ⇒ Node::Context
Create a context for the root of a document.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#document ⇒ Document
The OpenAPI document associated with this context.
-
#initialize(input, document_location:, source_location:) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ String
-
#location_summary ⇒ String
A string representing the location of the node.
-
#node ⇒ Node::Object, ...
Return the node for this context.
-
#resolved_input ⇒ Any
Used to return the data at this document location with all references resolved and optional fields populated with defaults.
-
#source ⇒ Source
The source file used to provide the data for this node.
-
#to_s ⇒ String
A string representing the location of the node.
Constructor Details
#initialize(input, document_location:, source_location:) ⇒ Context
Returns a new instance of Context.
62 63 64 65 66 |
# File 'lib/openapi3_parser/node/context.rb', line 62 def initialize(input, document_location:, source_location:) @input = input @document_location = document_location @source_location = source_location end |
Instance Attribute Details
#document_location ⇒ Source::Location (readonly)
The location in the root source of this node
17 18 19 |
# File 'lib/openapi3_parser/node/context.rb', line 17 def document_location @document_location end |
#input ⇒ Any (readonly)
The raw data that was used to build the node
17 18 19 |
# File 'lib/openapi3_parser/node/context.rb', line 17 def input @input end |
#source_location ⇒ Source::Location (readonly)
The location in a source file of this
17 18 19 |
# File 'lib/openapi3_parser/node/context.rb', line 17 def source_location @source_location end |
Class Method Details
.next_field(parent_context, field, factory_context) ⇒ Node::Context
Create a context for the child of a previous context
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/openapi3_parser/node/context.rb', line 35 def self.next_field(parent_context, field, factory_context) document_location = Source::Location.next_field( parent_context.document_location, field ) new(factory_context.input, document_location: document_location, source_location: factory_context.source_location) end |
.resolved_reference(current_context, reference_factory_context) ⇒ Node::Context
Create a context for a the a field that is the result of a reference
51 52 53 54 55 |
# File 'lib/openapi3_parser/node/context.rb', line 51 def self.resolved_reference(current_context, reference_factory_context) new(reference_factory_context.input, document_location: current_context.document_location, source_location: reference_factory_context.source_location) end |
.root(factory_context) ⇒ Node::Context
Create a context for the root of a document
22 23 24 25 26 27 |
# File 'lib/openapi3_parser/node/context.rb', line 22 def self.root(factory_context) location = Source::Location.new(factory_context.source, []) new(factory_context.input, document_location: location, source_location: factory_context.source_location) end |
Instance Method Details
#==(other) ⇒ Boolean
69 70 71 72 73 |
# File 'lib/openapi3_parser/node/context.rb', line 69 def ==(other) input == other.input && document_location == other.document_location && source_location == other.source_location end |
#document ⇒ Document
The OpenAPI document associated with this context
78 79 80 |
# File 'lib/openapi3_parser/node/context.rb', line 78 def document document_location.source.document end |
#inspect ⇒ String
90 91 92 93 |
# File 'lib/openapi3_parser/node/context.rb', line 90 def inspect %{#{self.class.name}(document_location: #{document_location}, } + %{source_location: #{source_location})} end |
#location_summary ⇒ String
A string representing the location of the node
98 99 100 101 102 103 104 105 106 |
# File 'lib/openapi3_parser/node/context.rb', line 98 def location_summary summary = document_location.to_s if document_location != source_location summary += " (#{source_location})" end summary end |
#node ⇒ Node::Object, ...
Return the node for this context
124 125 126 |
# File 'lib/openapi3_parser/node/context.rb', line 124 def node document.node_at(document_location.pointer) end |
#resolved_input ⇒ Any
Used to return the data at this document location with all references resolved and optional fields populated with defaults
117 118 119 |
# File 'lib/openapi3_parser/node/context.rb', line 117 def resolved_input document.resolved_input_at(document_location.pointer) end |
#source ⇒ Source
The source file used to provide the data for this node
85 86 87 |
# File 'lib/openapi3_parser/node/context.rb', line 85 def source source_location.source end |
#to_s ⇒ String
A string representing the location of the node
109 110 111 |
# File 'lib/openapi3_parser/node/context.rb', line 109 def to_s location_summary end |