Class: URI::Generic
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_path(path:, scheme: "file") ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/core_ext/uri.rb', line 10 def from_path(path:, scheme: "file") # On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI escaped_path = if /^[A-Z]:/.match?(path) DEFAULT_PARSER.escape("/#{path}") else DEFAULT_PARSER.escape(path) end build(scheme: scheme, path: escaped_path) end |
Instance Method Details
#storage_key ⇒ Object
41 42 43 |
# File 'lib/core_ext/uri.rb', line 41 def storage_key T.must(to_standardized_path || opaque) end |
#to_standardized_path ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/core_ext/uri.rb', line 25 def to_standardized_path parsed_path = path return unless parsed_path # On Windows, when we're getting the file system path back from the URI, we need to remove the leading forward # slash actual_path = if %r{^/[A-Z]:}.match?(parsed_path) parsed_path.delete_prefix("/") else parsed_path end CGI.unescape(actual_path) end |