Sha256: 71bb3044ec2f68240e2dae45a87e5fb1fc63284bb613bfd3f7e1fe19ea72da13

Contents?: true

Size: 796 Bytes

Versions: 17

Compression:

Stored size: 796 Bytes

Contents

module Steep
  module PathHelper
    module_function

    URIParser = URI::RFC2396_Parser.new()

    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

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

    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
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
steep-1.10.0 lib/steep/path_helper.rb
steep-1.10.0.pre.3 lib/steep/path_helper.rb
steep-1.10.0.pre.2 lib/steep/path_helper.rb
steep-1.10.0.pre.1 lib/steep/path_helper.rb
steep-1.10.0.dev.1 lib/steep/path_helper.rb
steep-relaxed-1.9.4.3 lib/steep/path_helper.rb
steep-relaxed-1.9.3.3 lib/steep/path_helper.rb
steep-activesupport-4-1.9.4 lib/steep/path_helper.rb
steep-activesupport-4-1.9.3.1 lib/steep/path_helper.rb
steep-1.9.4 lib/steep/path_helper.rb
steep-activesupport-4-1.9.3 lib/steep/path_helper.rb
steep-1.9.3 lib/steep/path_helper.rb
steep-1.9.2 lib/steep/path_helper.rb
steep-1.9.1 lib/steep/path_helper.rb
steep-1.9.0 lib/steep/path_helper.rb
steep-1.9.0.dev.2 lib/steep/path_helper.rb
steep-1.9.0.dev.1 lib/steep/path_helper.rb