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.
Constant Summary collapse
- UNDEFINED =
Class.new
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, given_input = UNDEFINED) ⇒ 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.
69 70 71 72 73 74 75 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 69 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.
64 65 66 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 64 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, given_input = UNDEFINED) ⇒ Context
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 36 def self.next_field(parent_context, field, given_input = UNDEFINED) pc = parent_context input = if given_input == UNDEFINED pc.input.respond_to?(:[]) ? pc.input[field] : nil else given_input end source_location = Source::Location.next_field(pc.source_location, field) new(input, 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 54 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:, reference_locations:) end |
Instance Method Details
#==(other) ⇒ Boolean
78 79 80 81 82 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 78 def ==(other) input == other.input && source_location == other.source_location && reference_locations == other.reference_locations end |
#inspect ⇒ Object
104 105 106 107 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 104 def inspect %{#{self.class.name}(source_location: #{source_location}, } + %{referenced_by: #{reference_locations.map(&:to_s).join(', ')})} end |
#location_summary ⇒ Object
109 110 111 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 109 def location_summary source_location.to_s end |
#resolve_reference(reference, factory, recursive: false) ⇒ Source::ResolvedReference
93 94 95 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 93 def resolve_reference(reference, factory, recursive: false) source.resolve_reference(reference, factory, self, recursive:) end |
#self_referencing? ⇒ Boolean
Used to show when an recursive reference loop has begun
100 101 102 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 100 def self_referencing? reference_locations.include?(source_location) end |
#source ⇒ Source
85 86 87 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 85 def source source_location.source end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/openapi3_parser/node_factory/context.rb', line 113 def to_s location_summary end |