Cuprum::Cli

A command-line utility powered by Cuprum that provides tools and utilities for defining command-line tools.

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

Returns

Back To Top

Instance Attributes

#files => Hash{String => Hash, IO} (readonly)

Returns

#root_path => String (readonly)

Inherited From
Cuprum::Cli::Dependencies::FileSystem

Returns

#tempfiles => Array<String> (readonly)

Returns

Back To Top

Instance Methods

#create_directory(path, recursive: false) => String

Also known as: make_directory

Creates a directory at the requested path.

Parameters

Returns

#directory?(path) => true, false

Also known as: directory_exists?

Checks if the requested directory exists.

Parameters

Returns

#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
  • (nil)

#file?(path) => true, false

Also known as: file_exists?

Checks if the requested directory exists.

Parameters

Returns

#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

Returns

#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