Class: Cuprum::Cli::Dependencies::FileSystem::Mock
- Parent Namespace
- Cuprum::Cli::Dependencies::FileSystem
- Inherited Classes
- Cuprum::Cli::Dependencies::FileSystem
>
Object
- Defined In
- lib/cuprum/cli/dependencies/file_system/mock.rb
Table Of Contents
Overview
Mock implementation of FileSystem for testing purposes.
Back To Top
Defined Under Namespace
- Classes
- InvalidPathError,
MockTempfile
Back To Top
Constructor
#initialize(files: {}, root_path: Dir.pwd) => Mock
Parameters
- files (Hash{String => Hash, IO}) — the mocked directories and files.
Must be a Hash with String keys representing file path segments; Hash
values represent directories, while IO values represent files.
- root_path (String) — the path to the root directory. Defaults to the
value of `Dir.pwd`.
Returns
- (Mock) — a new instance of Mock
Back To Top
Instance Attributes
#files => Hash{String => Hash, IO} (readonly)
Returns
- (Hash{String => Hash, IO}) — the mocked directories and files.
#root_path => String (readonly)
- Inherited From
- Cuprum::Cli::Dependencies::FileSystem
Returns
- (String) — the path to the root directory.
#tempfiles => Array<String> (readonly)
Returns
- (Array<String>) — the contents of each generated tempfile.
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 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.
#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.
Raises
#with_tempfile(&block) => 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.
Raises
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Dependencies
|
Cuprum::Cli::Dependencies::FileSystem