Class: Folio::Directory

Inherits:
FileObject show all
Defined in:
lib/folio/directory.rb

Constant Summary

Constants inherited from FileObject

FileObject::Separator

Instance Attribute Summary

Attributes inherited from FileObject

#path

Instance Method Summary collapse

Methods inherited from FileObject

#<=>, #==, [], #atime, #basename, #blockdev?, #chardev?, #chmod, #chown, #cp, #ctime, #dirname, #document?, #exist?, #extname, #fnmatch, #grpowned?, #identical?, #inspect, #install, #link, #link_force, #mtime, #owned?, #parent, #pipe?, #readable?, #readable_real?, #relative, #rename, #restat, #setgid?, #setuid?, #size, #size?, #socket?, #split, #stat, #sticky?, #symlink, #symlink_force, #to_s, #touch, #unlink_force, #utime, #writable?, #writable_real?, #zero?

Constructor Details

#initialize(path = nil) ⇒ Directory

Returns a new instance of Directory.



7
8
9
10
# File 'lib/folio/directory.rb', line 7

def initialize(path=nil)
  super(path || Dir.pwd)
  assert_exists if ::File.exist?(@path)
end

Instance Method Details

#/(fname) ⇒ Object Also known as: +

Join path and return new file object.



128
129
130
# File 'lib/folio/directory.rb', line 128

def /(fname)
  FileObject[path, fname]
end

#assert_existsObject

Raises:



12
13
14
# File 'lib/folio/directory.rb', line 12

def assert_exists
  raise FileNotFound unless ::File.directory?(@path)
end

#chdir(&block) ⇒ Object Also known as: cd

Change into this directory.



78
79
80
# File 'lib/folio/directory.rb', line 78

def chdir(&block)
  ::Dir.chdir(path, &block)
end

#chmod_r(mode) ⇒ Object

Change the mode of this directory and all it’s content recursively.



61
62
63
# File 'lib/folio/directory.rb', line 61

def chmod_r(mode)
  util.chmod_r(mode, path)
end

#chown_r(user, group) ⇒ Object

Change the owner of this directory and all it’s content recursively.



68
69
70
# File 'lib/folio/directory.rb', line 68

def chown_r(user, group)
  util.chown_r(user, group, path)
end

#chroot(&block) ⇒ Object

Make this directory the file system root.



84
85
86
# File 'lib/folio/directory.rb', line 84

def chroot(&block)
  ::Dir.chroot(path, &block)
end

#cp_r(dest) ⇒ Object

Copy this directory recursively to destination.



27
28
29
# File 'lib/folio/directory.rb', line 27

def cp_r(dest)
  util.cp_r(path, dest)
end

#directoriesObject

Returns an Enumerator over all directories in the directory.



123
124
125
# File 'lib/folio/directory.rb', line 123

def directories
  directory_entries.map{ |f| FileObject[path, f] }
end

#directory?Boolean

Returns:

  • (Boolean)


16
# File 'lib/folio/directory.rb', line 16

def directory?   ; true  ; end

#directory_entriesObject

Returns a list of directory names. This does not include ‘.’ or ‘..’.



106
107
108
109
110
# File 'lib/folio/directory.rb', line 106

def directory_entries
  entries.select{|f| File.directory?(File.join(path,f)) }
  #dirs = ::Dir.glob("#{path}/")
  #dirs.collect{ |f| f.chomp('/') }
end

#document_entriesObject

Returns a list of document names.



100
101
102
# File 'lib/folio/directory.rb', line 100

def document_entries
  entries.select{|f| File.file?(File.join(path,f)) }
end

#documentsObject

Returns an Enumerator over all documents in the directory.



118
119
120
# File 'lib/folio/directory.rb', line 118

def documents
  document_entries.map{ |f| FileObject[path, f] }
end

#entriesObject

This returns a list of file names. Unlike traditional Dir.entries method, this does not include ‘.’ or ‘..’.



95
96
97
# File 'lib/folio/directory.rb', line 95

def entries
  ::Dir.entries(path) - ['.', '..']
end

#filesObject

Returns an Enumerator over all file objects in the directory.



113
114
115
# File 'lib/folio/directory.rb', line 113

def files
  entries.map{ |f| FileObject[path, f] }
end

#foreach(&block) ⇒ Object

Loop over the entries (this does includes ‘.’ and ‘..’).



89
90
91
# File 'lib/folio/directory.rb', line 89

def foreach(&block)
  ::Dir.foreach(path, &block)
end

#rm_rObject

Remove this directory and all it’s content.



40
41
42
# File 'lib/folio/directory.rb', line 40

def rm_r
  util.rm_r(path)
end

#rm_rf(list) ⇒ Object

Remove this directory and all it’s content forcefully.



45
46
47
# File 'lib/folio/directory.rb', line 45

def rm_rf(list)
  util.rm_rf(path)
end

#rmdirObject Also known as: unlink, delete

Remove this directory. Fails if not empty.



32
33
34
# File 'lib/folio/directory.rb', line 32

def rmdir
  util.rmdir(path)
end

#shellObject

Opens up a Folio virtual shell at this directory.



19
20
21
# File 'lib/folio/directory.rb', line 19

def shell
  Folio::Shell.new(self)
end