lib/rio/ops/dir.rb in rio-0.3.7 vs lib/rio/ops/dir.rb in rio-0.3.8
- old
+ new
@@ -1,8 +1,8 @@
#--
# ===============================================================================
-# Copyright (c) 2005, Christopher Kleckner
+# Copyright (c) 2005, 2006 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
@@ -20,11 +20,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ===============================================================================
#++
#
# To create the documentation for Rio run the command
-# rake rdoc
+# ruby build_doc.rb
# from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
#
# Suggested Reading
# * RIO::Doc::SYNOPSIS
# * RIO::Doc::INTRO
@@ -38,61 +38,61 @@
require 'rio/grande'
require 'rio/cp'
require 'rio/ops/either'
module RIO
- module Impl
- module U
- def self.rmdir(s) ::Dir.rmdir(s.to_s) end
- def self.mkdir(s,*args) ::Dir.mkdir(s.to_s,*args) end
- def self.chdir(s,&block) ::Dir.chdir(s.to_s,&block) end
- def self.foreach(s,&block) ::Dir.foreach(s.to_s,&block) end
- def self.entries(s) ::Dir.entries(s.to_s) end
- def self.cp_r(s,d)
- require 'fileutils'
- ::FileUtils.cp_r(s.to_s,d.to_s)
- end
- def self.find(s,&block)
- require 'find'
- Find.find(s.to_s) do |f|
- yield f
- end
- end
- def self.glob(gstr,*args,&block)
- ::Dir.glob(gstr,*args,&block)
- end
- def self.rmtree(s)
- require 'fileutils'
- ::FileUtils.rmtree(s.to_s)
- end
- def self.mkpath(s)
- require 'fileutils'
- ::FileUtils.mkpath(s.to_s)
- end
- end
- end
+# module Impl
+# module U
+# def self.rmdir(s) ::Dir.rmdir(s.to_s) end
+# def self.mkdir(s,*args) ::Dir.mkdir(s.to_s,*args) end
+# def self.chdir(s,&block) ::Dir.chdir(s.to_s,&block) end
+# def self.foreach(s,&block) ::Dir.foreach(s.to_s,&block) end
+# def self.entries(s) ::Dir.entries(s.to_s) end
+# def self.cp_r(s,d)
+# require 'fileutils'
+# ::FileUtils.cp_r(s.to_s,d.to_s)
+# end
+# def self.find(s,&block)
+# require 'find'
+# Find.find(s.to_s) do |f|
+# yield f
+# end
+# end
+# def self.glob(gstr,*args,&block)
+# ::Dir.glob(gstr,*args,&block)
+# end
+# def self.rmtree(s)
+# require 'fileutils'
+# ::FileUtils.rmtree(s.to_s)
+# end
+# def self.mkpath(s)
+# require 'fileutils'
+# ::FileUtils.mkpath(s.to_s)
+# end
+# end
+# end
module Ops
module Dir
module ExistOrNot
- include ::RIO::Ops::FileOrDir::ExistOrNot
+ include RIO::Ops::FileOrDir::ExistOrNot
end
end
end
module Ops
module Dir
module NonExisting
include ExistOrNot
include ::RIO::Ops::FileOrDir::NonExisting
def mkdir(*args)
- # p callstr('mkdir',*args)
- Impl::U.mkdir(self,*args);
+ fs.mkdir(self.to_s,*args);
softreset()
end
def mkpath(*args)
# p callstr('mkpath',*args)
- Impl::U.mkpath(self,*args);
+ fs.mkpath(self.to_s,*args);
+ #fs.mkpath(self,*args);
softreset()
end
def rmdir(*args) self end
def rmtree(*args) self end
alias :delete :rmdir
@@ -122,47 +122,48 @@
module Dir
module Existing
def selective?
%w[entry_sel stream_sel stream_nosel].any? { |k| cx.has_key?(k) }
end
+ def empty?() self.to_a.empty? end
def mkdir(*args) self end
def mkpath(*args) self end
def rmdir(*args)
- Impl::U.rmdir(self,*args);
+ fs.rmdir(self.to_s,*args);
softreset()
end
- def rmtree(*args) Impl::U.rmtree(self,*args); softreset() end
+ def rmtree(*args) fs.rmtree(self.to_s,*args); softreset() end
alias :delete :rmdir
alias :delete! :rmtree
alias :unlink :rmdir
def chdir(*args,&block)
if block_given?
- Impl::U.chdir(self,*args) { |dir|
+ fs.chdir(self.to_s,*args) { |dir|
yield new_rio('.')
}
else
- Impl::U.chdir(self,*args)
+ fs.chdir(self.path,*args)
return new_rio('.')
end
self
end
-
+
def ensure_rio_cx(arg0)
return arg0 if arg0.kind_of?(::RIO::Rio)
new_rio_cx(arg0)
end
def glob(*args,&block)
chdir do
if block_given?
- Impl::U.glob(*args) do |ent|
+ fs.glob(*args) do |ent|
yield new_rio_cx(self,ent)
end
else
- return Impl::U.glob(*args).map { |ent| new_rio_cx(self,ent) }
+ return fs.glob(*args).map { |ent| new_rio_cx(self,ent) }
end
end
end
end
@@ -179,11 +180,10 @@
public
def entries(*args,&block) _set_select('entries',*args,&block) end
def each(*args,&block)
- # p callstr('each',*args)
each_(*args,&block)
end
def read()
@@ -228,14 +228,20 @@
#return unless cx.has_key?('skip_args') or cx['skipping']
return self unless cx.has_key?('skip_args')
args = cx['skip_args'] || []
self.skipentries(*args)
end
- def handle_ent_(estr,selfstr,sel,&block)
+ def ent_to_rio_(ent,indir)
+ if indir
+ new_rio_cx(indir.rl,ent)
+ else
+ new_rio_cx(ent)
+ end
+ end
+ def handle_ent_(ent,indir,sel,&block)
begin
- erio = new_rio_cx(selfstr ? Impl::U.join(selfstr,estr) : estr )
-
+ erio = ent_to_rio_(ent,indir)
if stream_iter?
_add_stream_iter_cx(erio).each(&block) if erio.file? and sel.match?(erio)
else
yield _add_iter_cx(erio) if sel.match?(erio)
end
@@ -251,23 +257,23 @@
end
def each_(*args,&block)
#p "#{callstr('each_',*args)} sel=#{cx['sel'].inspect} nosel=#{cx['nosel'].inspect}"
handle_skipped()
sel = Match::Entry::Selector.new(cx['entry_sel'])
- selfstr = (self.to_s == '.' ? nil : self.to_s)
- self.ioh.each do |estr|
- next if
- handle_ent_(estr,selfstr,sel,&block) unless estr =~ /^\.(\.)?$/
+ indir = (self.to_s == '.' ? nil : self)
+ self.ioh.each do |ent|
+ #next if
+ handle_ent_(ent,indir,sel,&block) unless ent =~ /^\.(\.)?$/
end
closeoneof? ? self.close : self
end
def each_ent_(*args,&block)
#p "#{callstr('each_',*args)} sel=#{cx['sel'].inspect} nosel=#{cx['nosel'].inspect}"
handle_skipped()
sel = Match::Entry::Selector.new(cx['entry_sel'])
- selfstr = (self.to_s == '.' ? nil : self.to_s)
- while estr = self.ioh.read
- handle_ent_(estr,selfstr,sel,&block) unless estr =~ /^\.(\.)?$/
+ indir = (self.to_s == '.' ? nil : self)
+ while ent = self.ioh.read
+ handle_ent_(ent,indir,sel,&block) unless ent =~ /^\.(\.)?$/
end
closeoneof? ? self.close : self
end
end