Class: Openapi3Parser::Context::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/context/location.rb

Overview

Class used to represent a location within an OpenAPI document. It contains a source, which is the source file/data used for the contents and the pointer which indicates where in the object like file the data is

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, pointer_segments) ⇒ Location

Returns a new instance of Location.

Parameters:



19
20
21
22
# File 'lib/openapi3_parser/context/location.rb', line 19

def initialize(source, pointer_segments)
  @source = source
  @pointer = Pointer.new(pointer_segments.freeze)
end

Instance Attribute Details

#pointerObject (readonly)

Returns the value of attribute pointer.



15
16
17
# File 'lib/openapi3_parser/context/location.rb', line 15

def pointer
  @pointer
end

#sourceObject (readonly)

Returns the value of attribute source.



15
16
17
# File 'lib/openapi3_parser/context/location.rb', line 15

def source
  @source
end

Class Method Details

.next_field(location, field) ⇒ Object



11
12
13
# File 'lib/openapi3_parser/context/location.rb', line 11

def self.next_field(location, field)
  new(location.source, location.pointer.segments + [field])
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/openapi3_parser/context/location.rb', line 24

def ==(other)
  source == other.source && pointer == other.pointer
end

#inspectObject



32
33
34
# File 'lib/openapi3_parser/context/location.rb', line 32

def inspect
  %{#{self.class.name}(source: #{source.inspect}, pointer: #{pointer})}
end

#to_sObject



28
29
30
# File 'lib/openapi3_parser/context/location.rb', line 28

def to_s
  source.relative_to_root + pointer.fragment
end