Module: RIO::IF::Dir

Included in:
Rio
Defined in:
lib/rio/if/dir.rb

Instance Method Summary collapse

Instance Method Details

#chdir(&block) ⇒ Object

Calls ::Dir#chdir.

Changes the current working directory of the process to the directory specified by the Rio. Raises a SystemCallError (probably Errno::ENOENT) if the target directory does not exist or if the Rio does not reference a directory.

If a block is given changes to the directory specified by the rio for the length of the block and changes back outside the block

Returns the Rio

rio('/home').chdir  # change the current working directory to /home
# the working directory here is /home
rio('/tmp/data/mydata').delete!.mkpath.chdir {
   # the working directory here is /tmp/data/mydata
}
# the working directory here is /home


46
# File 'lib/rio/if/dir.rb', line 46

def chdir(&block) target.chdir(&block);self end

#find(*args, &block) ⇒ Object

Calls Find#find

Uses ::Find#find to find all entries recursively for a Rio that specifies a directory. Note that there are other ways to recurse through a directory structure using a Rio. See #each and #all.

Calls the block passing a Rio for each entry found. The Rio inherits file attrubutes from the directory Rio.

Returns itself

rio('adir').find { |entrio| puts "#{entrio}: #{entrio.file?}" }

rio('adir').chomp.find do |entrio|
  next unless entrio.file?
  lines = entrio[0..10]  # lines are chomped because 'chomp' was inherited
end


68
# File 'lib/rio/if/dir.rb', line 68

def find(*args,&block) target.find_entries(*args,&block); self end

#glob(string, *args, &block) ⇒ Object

Calls ::Dir#glob

Returns the filenames found by expanding the pattern given in string, either as an array or as parameters to the block. In both cases the filenames are expressed as a Rio. Note that this pattern is not a regexp (it�s closer to a shell glob). See File::fnmatch for details of file name matching and the meaning of the flags parameter.



80
# File 'lib/rio/if/dir.rb', line 80

def glob(string,*args,&block) target.glob(string,*args,&block) end

#mkdir(*args, &block) ⇒ Object

Calls FileUtils#mkdir

Makes a new directory named by the Rio with permissions specified by the optional parameter. The permissions may be modified by the value of File::umask

Returns the Rio. If the directory already exists, just returns the Rio.

rio('adir').mkdir


133
# File 'lib/rio/if/dir.rb', line 133

def mkdir(*args,&block) target.mkdir(*args,&block); self end

#mkpath(&block) ⇒ Object

Calls FileUtils#mkpath

Makes a new directory named by the Rio and any directories in its path that do not exist.

Returns the Rio. If the directory already exists, just returns the Rio.

rio('adir/a/b').mkpath


122
# File 'lib/rio/if/dir.rb', line 122

def mkpath(&block) target.mkpath(&block); self end

#rmdirObject

Calls ::Dir#rmdir

Deletes the directory referenced by the Rio. Raises a subclass of SystemCallError if the directory isn�t empty. Returns the Rio. If the directory does not exist, just returns the Rio.

See also #rmtree, #delete, #delete!

rio('adir').rmdir # remove the empty directory 'adir'


93
# File 'lib/rio/if/dir.rb', line 93

def rmdir() target.rmdir(); self end

#rmtreeObject

Calls FileUtils#rmtree

Removes a directory Rio recursively. Returns the Rio. If the directory does not exist, simply returns the Rio

If called with a block, behaves as if rmtree.each(&block) had been called

See also #delete!

rio('adir').rmtree # removes the directory 'adir' recursively

# delete the directory 'adir', recreate it and then change to the new directory
rio('adir/asubdir').rmtree.mkpath.chdir {
  ...
}


113
# File 'lib/rio/if/dir.rb', line 113

def rmtree() target.rmtree(); self end