Class: GraphQL::Doctor::Location

Inherits:
Struct
  • Object
show all
Defined in:
lib/graphql/doctor/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Location

Returns a new instance of Location.



11
12
13
14
# File 'lib/graphql/doctor/location.rb', line 11

def initialize(**attributes)
  super
  freeze
end

Instance Attribute Details

#end_columnObject

Returns the value of attribute end_column

Returns:

  • (Object)

    the current value of end_column



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def end_column
  @end_column
end

#end_lineObject

Returns the value of attribute end_line

Returns:

  • (Object)

    the current value of end_line



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def end_line
  @end_line
end

#end_offsetObject

Returns the value of attribute end_offset

Returns:

  • (Object)

    the current value of end_offset



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def end_offset
  @end_offset
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def path
  @path
end

#start_columnObject

Returns the value of attribute start_column

Returns:

  • (Object)

    the current value of start_column



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def start_column
  @start_column
end

#start_lineObject

Returns the value of attribute start_line

Returns:

  • (Object)

    the current value of start_line



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def start_line
  @start_line
end

#start_offsetObject

Returns the value of attribute start_offset

Returns:

  • (Object)

    the current value of start_offset



7
8
9
# File 'lib/graphql/doctor/location.rb', line 7

def start_offset
  @start_offset
end

Class Method Details

.from_h(hash) ⇒ Object



28
29
30
# File 'lib/graphql/doctor/location.rb', line 28

def self.from_h(hash)
  new(**hash.transform_keys(&:to_sym))
end

.from_prism(path, location) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/graphql/doctor/location.rb', line 16

def self.from_prism(path, location)
  new(
    path: path,
    start_line: location.start_line,
    end_line: location.end_line,
    start_column: location.start_column,
    end_column: location.end_column,
    start_offset: location.start_offset,
    end_offset: location.end_offset
  )
end

Instance Method Details

#code_units_columns(encoding = Encoding::UTF_16LE, source: nil) ⇒ Object



44
45
46
47
48
49
# File 'lib/graphql/doctor/location.rb', line 44

def code_units_columns(encoding = Encoding::UTF_16LE, source: nil)
  source ||= Prism.parse(File.binread(path)).source
  [source.code_units_column(start_offset, encoding), source.code_units_column(end_offset, encoding)]
rescue SystemCallError, EncodingError, RuntimeError
  [start_column, end_column]
end

#end_code_units_column(encoding = Encoding::UTF_16LE) ⇒ Object



40
41
42
# File 'lib/graphql/doctor/location.rb', line 40

def end_code_units_column(encoding = Encoding::UTF_16LE)
  code_units_columns(encoding).last
end

#start_code_units_column(encoding = Encoding::UTF_16LE) ⇒ Object



36
37
38
# File 'lib/graphql/doctor/location.rb', line 36

def start_code_units_column(encoding = Encoding::UTF_16LE)
  code_units_columns(encoding).first
end

#to_hObject



32
33
34
# File 'lib/graphql/doctor/location.rb', line 32

def to_h
  members.to_h { |name| [name, public_send(name)] }
end