Class: Openapi3Parser::Context
- Inherits:
-
Object
- Object
- Openapi3Parser::Context
- Defined in:
- lib/openapi3_parser/context.rb,
lib/openapi3_parser/context/pointer.rb,
lib/openapi3_parser/context/location.rb
Overview
Context is a construct used in both the node factories and the nodes themselves. It is used to represent the data, and the source of it, that a node is associated with. It also acts as a bridge between a node/node factory and associated document.
Defined Under Namespace
Instance Attribute Summary collapse
-
#document_location ⇒ Context::Location
readonly
The current value of document_location.
-
#input ⇒ Object
readonly
The current value of input.
-
#referenced_by ⇒ Context?
readonly
The current value of referenced_by.
-
#source_location ⇒ Context::Location?
readonly
The current value of source_location.
Class Method Summary collapse
-
.next_field(parent_context, field) ⇒ Context
Create a context for a field within the current contexts data eg for a context of: root = Context.root({ “test” => {} }, source) we can get the context of “test” with: test = Context.next_field(root, “test”).
-
.reference_field(referencer_context, input:, source:, pointer_segments:) ⇒ Context
Creates the context for a field that is referenced by a context.
-
.root(input, source) ⇒ Context
Create a context for the root of a document.
Instance Method Summary collapse
- #document ⇒ Document
-
#initialize(input, document_location:, source_location: nil, referenced_by: nil) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #location_summary ⇒ Object
- #namespace ⇒ Object deprecated Deprecated.
- #register_reference(reference, factory) ⇒ Source::ReferenceResolver
- #source ⇒ Source
- #to_s ⇒ Object
Constructor Details
#initialize(input, document_location:, source_location: nil, referenced_by: nil) ⇒ Context
Returns a new instance of Context.
66 67 68 69 70 71 72 73 74 |
# File 'lib/openapi3_parser/context.rb', line 66 def initialize(input, document_location:, source_location: nil, referenced_by: nil) @input = input @document_location = document_location @source_location = source_location || document_location @referenced_by = referenced_by end |
Instance Attribute Details
#document_location ⇒ Context::Location (readonly)
Returns the current value of document_location.
15 16 17 |
# File 'lib/openapi3_parser/context.rb', line 15 def document_location @document_location end |
#input ⇒ Object (readonly)
Returns the current value of input.
15 16 17 |
# File 'lib/openapi3_parser/context.rb', line 15 def input @input end |
#referenced_by ⇒ Context? (readonly)
Returns the current value of referenced_by.
15 16 17 |
# File 'lib/openapi3_parser/context.rb', line 15 def referenced_by @referenced_by end |
#source_location ⇒ Context::Location? (readonly)
Returns the current value of source_location.
15 16 17 |
# File 'lib/openapi3_parser/context.rb', line 15 def source_location @source_location end |
Class Method Details
.next_field(parent_context, field) ⇒ Context
32 33 34 35 36 37 38 39 |
# File 'lib/openapi3_parser/context.rb', line 32 def self.next_field(parent_context, field) pc = parent_context input = pc.input.respond_to?(:[]) ? pc.input[field] : nil new(input, document_location: Location.next_field(pc.document_location, field), source_location: Location.next_field(pc.source_location, field), referenced_by: pc.referenced_by) end |
.reference_field(referencer_context, input:, source:, pointer_segments:) ⇒ Context
Creates the context for a field that is referenced by a context. In this scenario the context of the document is the same but we are in a different part of the source file, or even a different source file
50 51 52 53 54 55 56 57 58 |
# File 'lib/openapi3_parser/context.rb', line 50 def self.reference_field(referencer_context, input:, source:, pointer_segments:) new(input, document_location: referencer_context.document_location, source_location: Location.new(source, pointer_segments), referenced_by: referencer_context) end |
Instance Method Details
#document ⇒ Document
77 78 79 |
# File 'lib/openapi3_parser/context.rb', line 77 def document document_location.source.document end |
#inspect ⇒ Object
96 97 98 99 100 |
# File 'lib/openapi3_parser/context.rb', line 96 def inspect %{#{self.class.name}(document_location: #{document_location}, } + %{source_location: #{source_location}), referenced_by: } + %{#{referenced_by})} end |
#location_summary ⇒ Object
102 103 104 105 106 |
# File 'lib/openapi3_parser/context.rb', line 102 def location_summary summary = document_location.to_s summary += " (#{source_location})" if document_location != source_location summary end |
#namespace ⇒ Object
92 93 94 |
# File 'lib/openapi3_parser/context.rb', line 92 def namespace document_location.pointer.segments end |
#register_reference(reference, factory) ⇒ Source::ReferenceResolver
87 88 89 |
# File 'lib/openapi3_parser/context.rb', line 87 def register_reference(reference, factory) source.register_reference(reference, factory, self) end |
#source ⇒ Source
82 83 84 |
# File 'lib/openapi3_parser/context.rb', line 82 def source source_location.source end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/openapi3_parser/context.rb', line 108 def to_s location_summary end |