Class: Folio::Document
- Inherits:
-
FileObject
- Object
- FileObject
- Folio::Document
- Defined in:
- lib/folio/document.rb
Overview
Document
The Document class represents a FileObject.
Constant Summary
Constants inherited from FileObject
Instance Attribute Summary
Attributes inherited from FileObject
Instance Method Summary collapse
-
#append(string) ⇒ Object
(also: #<<)
Replace contents of file with string.
-
#assert_exists ⇒ Object
def intialize(path) super end.
- #delete ⇒ Object
-
#document? ⇒ Boolean
def file? ; true ; end.
-
#executable? ⇒ Boolean
- – FileTest
-
++.
- #executable_real? ⇒ Boolean
-
#open(mode, &block) ⇒ Object
– File.open ++.
-
#read ⇒ Object
Read file in as a string.
-
#readlines ⇒ Object
Read file in as an array of lines.
- #truncate(size) ⇒ Object
-
#unlink ⇒ Object
TODO: how to handle unkinking (b/c file no longer exists).
-
#write(string) ⇒ Object
(also: #<)
Replace contents of file with string.
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_exists ⇒ Object
def intialize(path)
super
end
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 |
#delete ⇒ Object
42 |
# File 'lib/folio/document.rb', line 42 def delete ; ::File.delete(path) ; end |
#document? ⇒ Boolean
def file? ; true ; end
21 |
# File 'lib/folio/document.rb', line 21 def document? ; true ; end |
#executable? ⇒ Boolean
–
- FileTest
-
++
27 |
# File 'lib/folio/document.rb', line 27 def executable? ; ::FileTest.executable?(path) ; end |
#executable_real? ⇒ 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 |
#read ⇒ Object
Read file in as a string.
35 |
# File 'lib/folio/document.rb', line 35 def read ; ::File.read(path) ; end |
#readlines ⇒ Object
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 |
#unlink ⇒ Object
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 |