lib/rio/rl/path.rb in rio-0.3.1 vs lib/rio/rl/path.rb in rio-0.3.2
- old
+ new
@@ -55,12 +55,23 @@
@pth = $2 || '/'
else
@pth = pth
@uri= nil
end
+ @pth.sub!(%r|/\.$|,'/')
+ @wd = nil
+ if !args.empty? and args[-1].kind_of?(::Hash) and (b = args.pop['base'])
+ @wd = case b
+ when %r%^file://(localhost)?(/.*)?$% then $2 || '/'
+ when %r%^/% then b
+ else RL.fs2url(::Dir.getwd)+'/'+b
+ end
+ @wd.squeeze('/')
+ end
self.join(*args) unless args.empty?
- @wd = RL.fs2url(::Dir.getwd)+'/'
+ @wd = @pth if @pth[0] == ?/
+ @wd = RL.fs2url(::Dir.getwd)+'/' unless @wd
end
def parse_url(str)
::URI.parse(::URI.escape(str,ESCAPE))
end
@@ -96,11 +107,10 @@
end
end
def to_s() RL.url2fs(@pth) end
def self.splitrl(s)
-
sch,opq,whole = split_riorl(s)
case sch
when 'file' then [whole]
else [opq]
end
@@ -122,10 +132,15 @@
rtrl
end
def merge(other)
self.class.new(uri.merge(other.uri))
end
- def base() (absolute? ? @pth : @wd) end
+ def base(arg=nil)
+ unless arg.nil?
+ self.wd = arg
+ end
+ (absolute? ? @pth : @wd)
+ end
def abs()
return self if absolute?
self.class.new(@wd + @pth)
end