Class: Openapi3Parser::Source::Location

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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:



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

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.



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

def pointer
  @pointer
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Class Method Details

.next_field(location, field) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  return false unless other.instance_of?(self.class)

  source == other.source && pointer == other.pointer
end

#dataObject



37
38
39
# File 'lib/openapi3_parser/source/location.rb', line 37

def data
  source.data_at_pointer(pointer.segments)
end

#inspectObject



49
50
51
# File 'lib/openapi3_parser/source/location.rb', line 49

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

#pointer_defined?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/openapi3_parser/source/location.rb', line 41

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

#source_available?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/openapi3_parser/source/location.rb', line 45

def source_available?
  source.available?
end

#to_sObject



33
34
35
# File 'lib/openapi3_parser/source/location.rb', line 33

def to_s
  source.relative_to_root + pointer.fragment
end