Class: Folio::Document

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

Overview

Document

The Document class represents a FileObject.

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, #directory?, #dirname, #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?

Instance Method Details

#append(string) ⇒ Object Also known as: <<

Replace contents of file with string.



64
65
66
# File 'lib/folio/document.rb', line 64

def append(string)
  ::File.open(path, 'a'){|f| f.write(string)}
end

#assert_existsObject

def intialize(path)

super

end

Raises:



15
16
17
18
# File 'lib/folio/document.rb', line 15

def assert_exists
  raise FileNotFound.new(@path) unless ::File.file?(@path)
  raise FileNotFound.new(@path) if ::File.symlink?(@path)
end

#deleteObject



42
# File 'lib/folio/document.rb', line 42

def delete            ; ::File.delete(path)                ; end

#document?Boolean

def file? ; true ; end

Returns:

  • (Boolean)


21
# File 'lib/folio/document.rb', line 21

def document? ; true ; end

#executable?Boolean

FileTest

++

Returns:

  • (Boolean)


27
# File 'lib/folio/document.rb', line 27

def executable?       ; ::FileTest.executable?(path)       ; end

#executable_real?Boolean

Returns:

  • (Boolean)


28
# File 'lib/folio/document.rb', line 28

def executable_real?  ; ::FileTest.executable_real?(path)  ; end

#open(mode, &block) ⇒ Object

– File.open ++



48
49
50
# File 'lib/folio/document.rb', line 48

def open(mode, &block)
  ::File.open(path, mode, &block)
end

#readObject

Read file in as a string.



35
# File 'lib/folio/document.rb', line 35

def read              ; ::File.read(path)                  ; end

#readlinesObject

Read file in as an array of lines.



38
# File 'lib/folio/document.rb', line 38

def readlines         ; ::File.readlines(path)             ; end

#truncate(size) ⇒ Object



52
53
54
# File 'lib/folio/document.rb', line 52

def truncate(size)
  ::File.open(path, 'w'){|f| f.truncate(size)}
end

TODO: how to handle unkinking (b/c file no longer exists)



41
# File 'lib/folio/document.rb', line 41

def unlink            ; ::File.unlink(path)                ; end

#write(string) ⇒ Object Also known as: <

Replace contents of file with string.



57
58
59
# File 'lib/folio/document.rb', line 57

def write(string)
  ::File.open(path, 'w'){|f| f.write(string)}
end