Module: PuppetLanguageServer::UriHelper
- Defined in:
- lib/puppet-languageserver/uri_helper.rb
Class Method Summary collapse
- .build_file_uri(path) ⇒ Object
-
.relative_uri_path(root_uri, uri, case_sensitive = true) ⇒ String
Compares two URIs and returns the relative path.
- .uri_path(uri_string) ⇒ Object
Class Method Details
.build_file_uri(path) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/puppet-languageserver/uri_helper.rb', line 8 def self.build_file_uri(path) if path.nil? nil else "file://#{Puppet::Util.uri_encode(path.start_with?('/') ? path : "/#{path}")}" end end |
.relative_uri_path(root_uri, uri, case_sensitive = true) ⇒ String
Compares two URIs and returns the relative path
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet-languageserver/uri_helper.rb', line 26 def self.relative_uri_path(root_uri, uri, case_sensitive = true) actual_root = URI(root_uri) actual_uri = URI(uri) return nil unless actual_root.scheme == actual_uri.scheme # CGI.unescape doesn't handle space rules properly in uri paths # URI::parser.unescape does, but returns strings in their original encoding # Mostly safe here as we're only worried about file based URIs parser = URI::DEFAULT_PARSER root_path = parser.unescape(actual_root.path) uri_path = parser.unescape(actual_uri.path) if case_sensitive return nil unless uri_path.slice(0, root_path.length) == root_path else return nil unless uri_path.slice(0, root_path.length).casecmp(root_path).zero? end uri_path.slice(root_path.length..-1) end |