Module: Steep::PathHelper

Defined in:
lib/steep/path_helper.rb

Constant Summary collapse

URIParser =
URI::RFC2396_Parser.new()

Class Method Summary collapse

Class Method Details

.to_pathname(uri, dosish: Gem.win_platform?) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/steep/path_helper.rb', line 7

def to_pathname(uri, dosish: Gem.win_platform?)
  uri = URI.parse(uri)
  if uri.scheme == "file"
    path = uri.path or raise
    path.sub!(%r{^/([a-zA-Z])(:|%3A)//?}i, '\1:/') if dosish
    path = URIParser.unescape(path)
    Pathname(path)
  end
end

.to_pathname!(uri, dosish: Gem.win_platform?) ⇒ Object



17
18
19
# File 'lib/steep/path_helper.rb', line 17

def to_pathname!(uri, dosish: Gem.win_platform?)
  to_pathname(uri, dosish: dosish) or raise "Cannot translate a URI to pathname: #{uri}"
end

.to_uri(path, dosish: Gem.win_platform?) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/steep/path_helper.rb', line 21

def to_uri(path, dosish: Gem.win_platform?)
  str_path = path.to_s
  if dosish
    str_path.insert(0, "/") if str_path[0] != "/"
  end
  str_path = URIParser.escape(str_path)
  URI::File.build(path: str_path)
end