Class: Cuprum::Cli::Dependencies::FileSystem
- Parent Namespace
- Cuprum::Cli::Dependencies
- Defined In
- lib/cuprum/cli/dependencies/file_system.rb
Table Of Contents
Overview
Utility wrapping filesystem operations.
Back To Top
Direct Subclasses
Cuprum::Cli::Dependencies::FileSystem::Mock
Back To Top
Defined Under Namespace
- Classes
- DirectoryIsAFileError,
DirectoryNotFoundError,
FileError,
FileIsADirectoryError,
FileNotFoundError,
Mock
Back To Top
Constructor
#initialize(root_path: Dir.pwd) => FileSystem
Parameters
- root_path (String) — the path to the root directory. Defaults to the
value of `Dir.pwd`.
Returns
- (FileSystem) — a new instance of FileSystem
Back To Top
Instance Attributes
#root_path => String (readonly)
Returns
- (String) — the path to the root directory.
Back To Top
Instance Methods
#create_directory(path, recursive: false) => String
Also known as:
make_directory
Creates a directory at the requested path.
Parameters
- path (String) — the path to the directory.
- recursive (true, false) — if true, creates any required intermediate
directories, equivalent to the -p flag on `mkdir`. Defaults to false.
Returns
- (String) — the path to the created directory.
#directory?(path) => true, false
Also known as:
directory_exists?
Checks if the requested directory exists.
Parameters
- path (String) — the path to the requested directory.
Returns
- (true, false) — true if the directory exists and is a directory,
otherwise false.
#each_file => Enumerator<String>
#each_file { |file| } => nil
Overloads
#each_file => Enumerator<String>
Iterates over file names matching the given pattern.
Parameters
- pattern (String) — the file pattern to match.
Returns
- (Enumerator<String>) — an enumerator over the matching file names.
#each_file { |file| } => nil
Yields each file name matching the given pattern.
Parameters
- pattern (String) — the file pattern to match.
Yield Parameters
- the (String) — matching file name.
Returns
#file?(path) => true, false
Also known as:
file_exists?
Checks if the requested file exists.
Parameters
- path (String) — the path to the requested file.
Returns
- (true, false) — true if the file exists and is a file,
otherwise false.
#read_file(file) => String
#read_file(path) => String
Also known as:
read
Overloads
#read_file(file) => String
Reads the contents of the given file or IO stream.
Parameters
- file (IO) — the file to read.
Returns
- (String) — the file contents.
#read_file(path) => String
Reads the contents of the file at the given path.
Parameters
- path (String) — the file path to read.
Returns
- (String) — the file contents.
Raises
- (FileIsADirectoryError) — if the requested file is a directory.
- (FileNotFoundError) — if the requested file is not found.
#with_tempfile(&) => Object
Creates a tempfile and passes it to the block.
Yield Parameters
- the (File) — generated tempfile.
Returns
- (Object) — the value returned by the block.
#write_file(file, data) => Integer
#write_file(path, data) => Integer
Also known as:
write
Overloads
#write_file(file, data) => Integer
Writes the data to the given file or IO stream.
Parameters
- file (IO) — the file to write.
- data (String) — the data to write.
Returns
- (Integer) — the number of bytes written.
#write_file(path, data) => Integer
Writes the data to the file at the given path.
Parameters
- path (String) — the file path to write.
- data (String) — the data to write.
Returns
- (Integer) — the number of bytes written.
Raises
- (DirectoryIsAFileError) — if the path to the requested file
includes an existing file.
- (DirectoryNotFoundError) — if the directory for the requested file
is not found.
- (FileIsADirectoryError) — if the requested file is a directory.
Back To Top
Back to
Documentation |
Versions |
0.1 |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Dependencies