class Torque::FileSystem
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
Public Class Methods
new()
click to toggle source
# File lib/torque/file_system.rb, line 17 def initialize # Do nothing; the file system's properties are by definition global end
Public Instance Methods
file_create(filename, over=false)
click to toggle source
Creates a file, optionally overwriting an existing file to do so
# 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)
click to toggle source
@return An iterator over each line of a file
# File lib/torque/file_system.rb, line 33 def file_each_line(filename) File.open(filename, "r").each_line end
file_read(filename)
click to toggle source
@return The contents of a file
# File lib/torque/file_system.rb, line 39 def file_read(filename) File.read(filename) end
file_write(filename, string)
click to toggle source
Writes a string to file
# File lib/torque/file_system.rb, line 45 def file_write(filename, string) File.write(filename, string) end
mkdir(dirname)
click to toggle source
Creates a directory
# File lib/torque/file_system.rb, line 51 def mkdir(dirname) FileUtils.mkdir(dirname) end
mkdir_p(dirname)
click to toggle source
Creates a directory, creating intermediate directories as needed
# File lib/torque/file_system.rb, line 57 def mkdir_p(dirname) FileUtils.mkdir_p(dirname) end
path_exist?(pathname)
click to toggle source
@param pathname The pathname to test
@return True if the pathname exists, else false
# File lib/torque/file_system.rb, line 65 def path_exist?(pathname) Pathname.new(pathname).exist? end