Class: Openapi3Parser::NodeFactory::Context
- Inherits:
-
Object
- Object
- Openapi3Parser::NodeFactory::Context
- Defined in:
- lib/openapi3_parser/node_factory/context.rb
Overview
This class is used to specify the data and source information for a NodeFactory. The same NodeFactory can be used multiple times if the object is referenced so it is limited in data about it’s location within the document.
Instance Attribute Summary collapse
-
#input ⇒ Any
readonly
The current value of input.
-
#reference_locations ⇒ Object
readonly
Returns the value of attribute reference_locations.
-
#refernce_locations ⇒ Array<Source::Location>
readonly
The current value of refernce_locations.
-
#source_location ⇒ Source::Location
readonly
The current value of source_location.
Class Method Summary collapse
-
.next_field(parent_context, field) ⇒ Context
Create a factory 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”).
-
.resolved_reference(reference_context, source_location:) ⇒ Context
Creates the context for a field that references another field.
-
.root(input, source) ⇒ Context
Create a context for the root of a document.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(input, source_location:, reference_locations: []) ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #location_summary ⇒ Object
- #resolve_reference(reference, factory, recursive: false) ⇒ Source::ResolvedReference
-
#self_referencing? ⇒ Boolean
Used to show when an recursive reference loop has begun.
- #source ⇒ Source
- #to_s ⇒ Object
Constructor Details
#initialize(input, source_location:, reference_locations: []) ⇒ Context
Returns a new instance of Context.
62 63 64 65 66 67 68 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 62 def initialize(input, source_location:, reference_locations: []) @input = input @source_location = source_location @reference_locations = reference_locations end |
Instance Attribute Details
#input ⇒ Any (readonly)
Returns the current value of input.
14 15 16 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 14 def input @input end |
#reference_locations ⇒ Object (readonly)
Returns the value of attribute reference_locations.
57 58 59 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 57 def reference_locations @reference_locations end |
#refernce_locations ⇒ Array<Source::Location> (readonly)
Returns the current value of refernce_locations.
14 15 16 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 14 def refernce_locations @refernce_locations end |
#source_location ⇒ Source::Location (readonly)
Returns the current value of source_location.
14 15 16 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 14 def source_location @source_location end |
Class Method Details
.next_field(parent_context, field) ⇒ Context
33 34 35 36 37 38 39 40 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 33 def self.next_field(parent_context, field) pc = parent_context input = pc.input.respond_to?(:[]) ? pc.input[field] : nil source_location = Source::Location.next_field(pc.source_location, field) new(input, source_location: source_location, reference_locations: pc.reference_locations) end |
.resolved_reference(reference_context, source_location:) ⇒ Context
Creates the context for a field that references another field
47 48 49 50 51 52 53 54 55 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 47 def self.resolved_reference(reference_context, source_location:) reference_locations = [reference_context.source_location] + reference_context.reference_locations data = source_location.data if source_location.source_available? new(data, source_location: source_location, reference_locations: reference_locations) end |
Instance Method Details
#==(other) ⇒ Boolean
71 72 73 74 75 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 71 def ==(other) input == other.input && source_location == other.source_location && reference_locations == other.reference_locations end |
#inspect ⇒ Object
97 98 99 100 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 97 def inspect %{#{self.class.name}(source_location: #{source_location}, } + %{referenced_by: #{reference_locations.map(&:to_s).join(', ')})} end |
#location_summary ⇒ Object
102 103 104 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 102 def location_summary source_location.to_s end |
#resolve_reference(reference, factory, recursive: false) ⇒ Source::ResolvedReference
86 87 88 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 86 def resolve_reference(reference, factory, recursive: false) source.resolve_reference(reference, factory, self, recursive: recursive) end |
#self_referencing? ⇒ Boolean
Used to show when an recursive reference loop has begun
93 94 95 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 93 def self_referencing? reference_locations.include?(source_location) end |
#source ⇒ Source
78 79 80 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 78 def source source_location.source end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 106 def to_s location_summary end |