lib/rio/path.rb in rio-0.3.7 vs lib/rio/path.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 @@ -47,10 +47,26 @@ # nil? or empty? => Emp # else => Sin class Empty < State::Base include Ops::Path::Empty def check?() fspath.nil? or fspath.empty? end + def [](*args) + self.rl = Path::RL.new('.') + softreset[*args] + end + def each(&block) + self.rl = Path::RL.new('.') + softreset.each(&block) + end + def read(*args) + self.rl = Path::RL.new('.') + softreset.read(*args) + end + def get(*args) + self.rl = Path::RL.new('.') + softreset.get(*args) + end def when_missing(sym,*args) gofigure(sym,*args) end end # Primary State for Rio as path manipulator class Str < State::Base @@ -66,52 +82,44 @@ when directory? then edir() else npath() end end - protected + private - def edir() - #rl.path += '/' unless rl.path.empty? or rl.path[-1] == ?/ - next_state = become('Dir::Existing') - next_state.extend(Ops::Symlink::Existing) if symlink? + def _fs_state(become_state,symlink_mod) + next_state = become(become_state) + next_state.extend(symlink_mod) if symlink? next_state end - def efile() - next_state = become('File::Existing') - next_state.extend(Ops::Symlink::Existing) if symlink? - next_state - end - def npath() - next_state = become('Path::NonExisting') - next_state.extend(Ops::Symlink::NonExisting) if symlink? - next_state - end - end # class PathString + protected + def edir() _fs_state('Dir::Existing',Ops::Symlink::Existing) end + def efile() _fs_state('File::Existing',Ops::Symlink::Existing) end + def npath() _fs_state('Path::NonExisting',Ops::Symlink::NonExisting) end + + end + # A transition state. Anything but simple path tests must cause a transition out of this state. class NonExisting < State::Base include Ops::Path::NonExisting include Cp::NonExisting::Output def check?() not exist? end - def ndir() - #rl.path += '/' unless rl.path.empty? or rl.path[-1] == ?/ - become('Dir::NonExisting') - end + def ndir() become 'Dir::NonExisting' end def nfile() become('File::NonExisting') end def when_missing(sym,*args) case sym when :mkdir,:mkpath ndir() else nfile() end end - end # class NPath + end - end # module Rsc + end end