Class: Openapi3Parser::Source::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/source/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:



17
18
19
20
# File 'lib/openapi3_parser/source/location.rb', line 17

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.



13
14
15
# File 'lib/openapi3_parser/source/location.rb', line 13

def pointer
  @pointer
end

#sourceObject (readonly)

Returns the value of attribute source.



13
14
15
# File 'lib/openapi3_parser/source/location.rb', line 13

def source
  @source
end

Class Method Details

.next_field(location, field) ⇒ Object



9
10
11
# File 'lib/openapi3_parser/source/location.rb', line 9

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

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
# File 'lib/openapi3_parser/source/location.rb', line 22

def ==(other)
  return false unless other.instance_of?(self.class)
  source == other.source && pointer == other.pointer
end

#dataObject



31
32
33
# File 'lib/openapi3_parser/source/location.rb', line 31

def data
  source.data_at_pointer(pointer.segments)
end

#inspectObject



43
44
45
# File 'lib/openapi3_parser/source/location.rb', line 43

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

#pointer_defined?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/openapi3_parser/source/location.rb', line 35

def pointer_defined?
  source.has_pointer?(pointer.segments)
end

#source_available?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/openapi3_parser/source/location.rb', line 39

def source_available?
  source.available?
end

#to_sObject



27
28
29
# File 'lib/openapi3_parser/source/location.rb', line 27

def to_s
  source.relative_to_root + pointer.fragment
end