lib/rio/ops/path.rb in rio-0.4.2 vs lib/rio/ops/path.rb in rio-0.5.1

- old
+ new

@@ -1,8 +1,8 @@ #-- -# =============================================================================== -# Copyright (c) 2005,2006,2007,2008 Christopher Kleckner +# =========================================================================== +# Copyright (c) 2005-2012 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 @@ -16,28 +16,28 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Rio; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# =============================================================================== +# =========================================================================== #++ # -# To create the documentation for Rio run the command -# ruby build_doc.rb -# from the distribution directory. -# -# Suggested Reading -# * RIO::Doc::SYNOPSIS -# * RIO::Doc::INTRO -# * RIO::Doc::HOWTO -# * RIO::Doc::EXAMPLES -# * RIO::Rio -# +require 'rio/fwd' #require 'rio/impl/path' +require 'rio/ops/create' +require 'rio/ops/construct' module RIO + module Ops + module Path + autoload :Create, 'rio/ops/create' + end + end +end + +module RIO module Ops #:nodoc: all module Path module Test def blockdev?(*args) fs.blockdev?(self.to_s,*args) end def chardev?(*args) fs.chardev?(self.to_s,*args) end @@ -88,16 +88,23 @@ #new_rio(rl,{:base => ensure_rio(base).abs.to_uri}).abs brio = ensure_rio(base) new_rio(rl.abs(ensure_rio(base).to_s)) end end - def abs? - rl.abs? + def absolute? + #p "ops/path.rb absolute?" + rl.absolute? end - alias :absolute? :abs? + alias :abs? :absolute? + #def abs? + # p "ops/path.rb abs?" + # rl.abs? + #end def route_from(other) - new_rio(rl.abs.route_from(ensure_rio(other).rl.abs)) + this_uri = rl.uri.abs + other_uri = ensure_rio(other).rl.uri.abs + new_rio(this_uri.route_from(other_uri)) end def rel(other=nil) if other.nil? base = self.abs.dirname else @@ -112,34 +119,54 @@ end def merge(other) new_rio(rl.merge(ensure_rio(other).rl)) end def base() + #p "BASE: " + rl.class.to_s new_rio(rl.base()) end def setbase(b) rl.base(b) self end extend Forwardable - def_instance_delegators(:rl,:scheme,:host,:opaque) + extend Fwd + fwd :rl,:scheme,:host,:user,:password + fwd :rl,:query,:fragment,:userinfo + fwd :rl,:typecode + fwd :rl,:authority end module Query + def normalize + rtn_rio { + uri.normalize + } + end + def expand_path(*args) args[0] = args[0].to_s unless args.empty? - new_rio(RL.fs2url(fs.expand_path(self.to_s,*args))) + new_rio(fs.expand_path(self.to_s,*args)) end def extname(*args) en = fs.extname(rl.path_no_slash,*args) (en.empty? ? nil : en) end def splitpath() require 'rio/to_rio' - parts = self.rl.split + sparts,bparts = self.rl.split + parts = [] + (0...sparts.length).each do |n| + parts << new_rio(sparts[n], {:base => bparts[n]}) + end + parts.extend(ToRio::Array) + #parts.each do |part| + # p "part=#{part.uri} abs=#{part.abs.uri}" + #end # map to rios and extend the array with to_array - parts.map { |arl| new_rio(arl) }.extend(ToRio::Array) + #parts.map { |arl| new_rio(arl) }.extend(ToRio::Array) + #parts.map { |arl| new_rio(arl) } end def basename(*args) unless args.empty? ex = args[0] || self.extname self.ext(ex) @@ -148,15 +175,19 @@ end def filename() new_rio(rl.filename) end def dirname(*args) - new_rio(rl.dirname) + new_rio(uri.dirname) end def sub(re,arg) - new_rio(softreset.to_s.sub(re,arg.to_s)) + rtn_rio { + softreset + uri.ref.sub(re,arg.to_s) + } + #new_rio(softreset.to_s.sub(re,arg.to_s)) end def gsub(re,arg) new_rio(softreset.to_s.gsub(re,arg.to_s)) end @@ -165,24 +196,24 @@ end private def _path_with_basename(arg) - old = rl.path_no_slash + old = rl.path old[0,old.length-basename.length-ext?.length]+arg.to_s+ext? end def _path_with_filename(arg) - old = rl.path_no_slash + old = rl.path old[0,old.length-filename.length]+arg.to_s end def _path_with_ext(ex) old = rl.path_no_slash old[0,old.length-ext?.length]+ex end def _path_with_dirname(arg) old = rl.path_no_slash - arg.to_s + old[-(old.length-dirname.length),old.length] + arg.to_s + old[-(old.length-dirname.length+1),old.length] end end module Change def sub!(*args) rl.path = rl.path.sub(*args) @@ -203,50 +234,50 @@ def filename=(arg) if cx['rename'] must_exist.filename = arg else - rl.urlpath = _path_with_filename(arg) + uri.filename = arg.to_s softreset end end def basename=(arg) if cx['rename'] must_exist.basename = arg else - rl.urlpath = _path_with_basename(arg) + uri.ext = cx['ext'] if cx.has_key?('ext') + uri.basename = arg.to_s softreset end end def extname=(arg) #p callstr('extname=',arg) if cx['rename'] must_exist.extname = arg else - rl.urlpath = _path_with_ext(arg) + uri.ext = cx['ext'] if cx.has_key?('ext') + uri.extname = arg.to_s softreset end end def dirname=(arg) if cx['rename'] must_exist.dirname = arg else - rl.path = _path_with_dirname(arg) + uri.dirname = arg.to_s softreset end end end end end end -require 'rio/ops/create' -require 'rio/ops/construct' module RIO module Ops module Path module Empty include Ops::Path::Create @@ -260,10 +291,10 @@ dst /= self.filename if dst.directory? if self.abs? fs.symlink(self,dst) else #p "symlink(#{dst.route_to(self)},#{dst})" - fs.symlink(dst.route_to(self),dst.to_s) + fs.symlink(dst.route_to(self).to_s,dst.to_s) end dst.reset } end end