Class: Torque::FileSystem
- Inherits:
-
Object
- Object
- Torque::FileSystem
- Defined in:
- lib/torque/file_system.rb
Overview
Creates a (limited) interface through which Torque can interact with the local file system
Supports:
-
File creation, reading, line-by-line iteration, and overwriting
-
Directory creation
-
Pathname checking
Instance Method Summary collapse
-
#file_create(filename, over = false) ⇒ Object
Creates a file, optionally overwriting an existing file to do so.
-
#file_each_line(filename) ⇒ Object
An iterator over each line of a file.
-
#file_read(filename) ⇒ Object
The contents of a file.
-
#file_write(filename, string) ⇒ Object
Writes a string to file.
-
#initialize ⇒ FileSystem
constructor
A new instance of FileSystem.
-
#mkdir(dirname) ⇒ Object
Creates a directory.
-
#mkdir_p(dirname) ⇒ Object
Creates a directory, creating intermediate directories as needed.
-
#path_exist?(pathname) ⇒ Boolean
True if the pathname exists, else false.
Constructor Details
#initialize ⇒ FileSystem
Returns a new instance of FileSystem.
17 18 19 |
# File 'lib/torque/file_system.rb', line 17 def initialize # Do nothing; the file system's properties are by definition global end |
Instance Method Details
#file_create(filename, over = false) ⇒ Object
Creates a file, optionally overwriting an existing file to do so
23 24 25 26 27 28 29 |
# File 'lib/torque/file_system.rb', line 23 def file_create(filename, over=false) if !path_exist? filename || over File.open(filename, "w") else raise IOError.new "File #{filename} already exists" end end |
#file_each_line(filename) ⇒ Object
Returns An iterator over each line of a file.
33 34 35 |
# File 'lib/torque/file_system.rb', line 33 def file_each_line(filename) File.open(filename, "r").each_line end |
#file_read(filename) ⇒ Object
Returns The contents of a file.
39 40 41 |
# File 'lib/torque/file_system.rb', line 39 def file_read(filename) File.read(filename) end |
#file_write(filename, string) ⇒ Object
Writes a string to file
45 46 47 |
# File 'lib/torque/file_system.rb', line 45 def file_write(filename, string) File.write(filename, string) end |
#mkdir(dirname) ⇒ Object
Creates a directory
51 52 53 |
# File 'lib/torque/file_system.rb', line 51 def mkdir(dirname) FileUtils.mkdir(dirname) end |
#mkdir_p(dirname) ⇒ Object
Creates a directory, creating intermediate directories as needed
57 58 59 |
# File 'lib/torque/file_system.rb', line 57 def mkdir_p(dirname) FileUtils.mkdir_p(dirname) end |
#path_exist?(pathname) ⇒ Boolean
Returns True if the pathname exists, else false.
65 66 67 |
# File 'lib/torque/file_system.rb', line 65 def path_exist?(pathname) Pathname.new(pathname).exist? end |