module URI::FileCommon
Constants
- BACKSLASH
- COLON
- COMPONENT
- DBL_BACKSLASH
- DBL_SLASH
- LOCALHOST
- SLASH
Public Class Methods
build(args)
click to toggle source
Calls superclass method
# File lib/file-uri/common.rb, line 14 def self.build(args) tmp = Util.make_components_hash(self, args) super(tmp) end
Public Instance Methods
local?(localhost: true)
click to toggle source
localhost:
* :any => any non-empty host is local * true => 'file://localhost/' is local, 'file://example.com/' is non-local * false => 'file://localhost/' is non-local
# File lib/file-uri/common.rb, line 26 def local? localhost: true if host && !host.empty? return true if localhost == :any return localhost && (host.downcase == LOCALHOST) elsif path && path.start_with?(DBL_SLASH) return false end true end
open(*args, localhost: :true, &block)
click to toggle source
open( [mode [, perm]] [, opt]) –> io or nil open( [mode [, perm]] [, opt]) {|io| block } –> obj
See Kernel#open, URI::File#to_file_path
# File lib/file-uri/common.rb, line 75 def open *args, localhost: :true, &block Kernel::open to_file_path(localhost: localhost), *args, &block end
to_file_path(localhost: true)
click to toggle source
localhost:
* :any => any non-empty host is local * true => 'file://localhost/' is local, 'file://example.com/' is non-local * false => 'file://localhost/' is non-local
# File lib/file-uri/common.rb, line 43 def to_file_path localhost: true raise "no local path for non-local URI #{to_s}" unless local?(localhost: localhost) path end
to_unc(localhost: true)
click to toggle source
localhost:
* :any => any non-empty host is local * true => 'file://localhost/' is local, 'file://example.com/' is non-local * false => 'file://localhost/' is non-local
# File lib/file-uri/common.rb, line 55 def to_unc localhost: true if host && !host.empty? if localhost != :any && (!localhost || (host.downcase != LOCALHOST)) unc = DBL_BACKSLASH + host unc += COLON + port if port unc += path.gsub(%r[/], BACKSLASH) return unc end elsif path.start_with? DBL_SLASH return path.gsub(%r[/], BACKSLASH) end raise "no UNC conversion for local URI #{to_s}" end