lib/rio/ops/dir.rb in rio-0.5.1 vs lib/rio/ops/dir.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
@@ -23,44 +23,12 @@
#
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 Ops
module Dir
module ExistOrNot
include RIO::Ops::FileOrDir::ExistOrNot
end
@@ -70,19 +38,15 @@
module Dir
module NonExisting
include ExistOrNot
include ::RIO::Ops::FileOrDir::NonExisting
def mkdir(*args)
- #p "ops/dir/mkdir: self=#{self.to_s}"
- #p "ops/dir/mkdir: self.path=#{self.path.inspect}"
fs.mkdir(self.path,*args);
softreset()
end
def mkpath(*args)
- # p callstr('mkpath',*args)
fs.mkpath(self.path,*args);
- #fs.mkpath(self,*args);
softreset()
end
def rmdir(*args) self end
def rmtree(*args) self end
alias :delete :rmdir
@@ -120,11 +84,10 @@
def rmdir(*args)
fs.rmdir(self.path,*args);
softreset()
end
def rmtree(*args) fs.rmtree(self.path,*args); softreset() end
- # def rm(*args) fs.rm(self.path,*args); softreset() end
alias :delete :rmdir
alias :unlink :delete
alias :delete! :rmtree
@@ -189,12 +152,13 @@
end
def rewind() ioh.rewind(); self end
def seek(integer) ioh.seek(integer); self end
- extend Forwardable
- def_instance_delegators(:ioh,:tell,:pos,:pos=)
+ extend RIO::Fwd
+ fwd_reader :ioh,:tell
+ fwd :ioh, :pos
protected
require 'rio/entrysel'
end
end
@@ -214,17 +178,15 @@
self.close if closeoneof?
nil
end
end
def handle_skipped
- #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 ent_to_rio_(ent,indir)
- #p "ent_to_rio: ent=#{ent.inspect} indir=#{indir}"
if ent.kind_of?(RIO::Rio)
oldpath = ent.to_s
ent.rl.urlpath = indir.to_s
ent.join!(oldpath)
ent.cx = self.cx.bequeath(ent.cx)
@@ -238,21 +200,17 @@
end
end
end
def handle_ent_(ent,indir,sel,&block)
begin
- #p "ENT=#{ent.inspect}"
- #p "FS=#{rl.fs.inspect}"
- #p "FS.ENCODING=#{rl.fs.encoding}"
ent.force_encoding(rl.fs.encoding)
erio = ent_to_rio_(ent,indir)
if stream_iter?
# case for iterating files in a directory (e.g. rio('adir').lines)
_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
- #p "handle_ent_2: #{erio.cx.inspect}"
if cx.has_key?('all') and erio.directory?
rsel = Match::Entry::SelectorClassic.new(cx['r_sel'],cx['r_nosel'])
_add_recurse_iter_cx(erio).each(&block) if rsel.match?(erio)
end