lib/rio/rl/withpath.rb in rio-0.5.1 vs lib/rio/rl/withpath.rb in rio-0.6.0
- old
+ new
@@ -1,8 +1,8 @@
#--
# ===========================================================================
-# Copyright (c) 2005-2012 Christopher Kleckner
+# Copyright (c) 2005-2017 Christopher Kleckner
# All rights reserved
#
# This file is part of the Rio library for ruby.
#
# Rio is free software; you can redistribute it and/or modify
@@ -98,23 +98,19 @@
end
module RIO
module RL
class WithPath < RIO::RL::Base
- #SCHEME = URI::REGEXP::PATTERN::SCHEME
- #HOST = URI::REGEXP::PATTERN::HOST
-
# returns the path as the file system sees it. Spaces are spaces and not
# %20 etc. This is the path that would be passed to the fs object.
# For windows RLs this includes the '//host' part and the 'C:' part
# returns a String
def fspath()
uri.netpath
end
def fspath=(fpth)
- #p "FSPATH= #{fpth} => #{RL.fs2url(fpth)}"
uri.netpath = fpth
end
def is_root?(upth)
upth =~ %r%^(/?[a-zA-Z]:)?/% or upth =~ %r%^//(#{HOST})%
@@ -130,11 +126,10 @@
def fspath_no_slash()
fspath.sub(%r{/*$},'')
end
def pathdepth()
pth = self.path_no_slash
- #is_root?(pth) ? 0 : pth.count('/')
pth.count('/')
end
def _uri(arg)
arg.kind_of?(::Alt::URI) ? arg.clone : ::Alt::URI.parse(arg.to_s)
@@ -145,18 +140,15 @@
# returns a RL
def abs(thebase=nil)
thebase ||= self.base
base_uri = _uri(thebase)
path_uri = self.uri.clone
- #p "abs: base_uri=#{base_uri.inspect}"
- #p "abs: path_uri=#{path_uri.inspect}"
if path_uri.scheme == 'file' and base_uri.scheme != 'file'
abs_uri = path_uri.abs(base_uri)
else
abs_uri = path_uri.abs(base_uri)
end
- #p "abs: abs_uri=#{abs_uri.inspect}"
_build(abs_uri,{:fs => self.fs})
end
# returns an array of parts of a RL.
@@ -192,15 +184,14 @@
}
rlparts
end
- # changes this RLs path so that is consists of this RL's path
+ # changes this RLs path so that it consists of this RL's path
# combined with those of its arguments.
def join(*args)
return self if args.empty?
- #sa = args.map { |arg| ::URI.escape(arg.to_s,ESCAPE) }
sa = args.map { |arg| arg.to_s }
join_(sa)
end
def join_(sa)
sa.unshift(self.urlpath) unless self.urlpath.empty?
@@ -211,19 +202,10 @@
# returns the directory portion of the path
# like File#dirname
# returns a RL
def dirname()
- #u = uri.clone
- #u.path = fs.dirname(uri.path).sub(%r{/*$},'/')
- #puts
- #if uri.scheme == 'file'
- # u.host = self.host
- #else
- # u.scheme = uri.scheme
- # u.host = uri.host
- #end
RIO::RL::Builder.build(uri.dirname)
end
# returns the tail portion of the path minus the extension
# returns a RL
@@ -258,20 +240,10 @@
def route_to(other) _build(self.uri.route_to(other.uri),{:base => self.uri}) end
def _build(*args) RIO::RL::Builder.build(*args) end
def uri_from_string_(str)
- #p "uri_from_string(#{str})"
::Alt::URI.parse(str)
- #case str
- #when %r%^file://(#{HOST})?(/.*)?$% then ::URI.parse(str)
- #when %r/^[a-zA-Z]:/ then
- # ::URI.parse(str)
- #when %r/^#{SCHEME}:/ then ::URI.parse(str)
- #when %r{^/} then ::URI.parse('file://'+str+( ( str[-1,0] == '/' ) ? "" : "/"))
- #when %r{^/} then ::URI.parse('file://'+RL.fs2url(str))
- #else ::URI.parse(str)
- #end
end
end
end
end