Module: RubyLens::Index::SourcePath

Defined in:
lib/rubylens/index/source_path.rb

Overview

Maps Rubydex document and location URIs back to workspace source paths.

Constant Summary collapse

COMPONENT_ROOTS =
%w[lib app test tests spec specs].freeze

Class Method Summary collapse

Class Method Details

.component_for(relative) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/rubylens/index/source_path.rb', line 28

def component_for(relative)
  segments = relative.split(File::SEPARATOR)
  first = segments.first || "root"
  if COMPONENT_ROOTS.include?(first)
    "#{first}/#{segments[1] || "root"}"
  else
    first
  end
end

.from_file_uri(uri_string) ⇒ Object

Rubydex 0.2.9 percent-encodes file URIs and Location#to_file_path returns the path still encoded, so decode the URI ourselves.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubylens/index/source_path.rb', line 15

def from_file_uri(uri_string)
  uri = URI.parse(uri_string)
  return unless uri.scheme == "file"
  return if uri.host && !uri.host.empty? && uri.host != "localhost"
  return unless uri.path

  path = URI::RFC2396_PARSER.unescape(uri.path)
  path = path.delete_prefix("/") if Gem.win_platform?
  path
rescue URI::InvalidURIError
  nil
end