Module: SnippetCli::FileHelper

Defined in:
lib/snippet_cli/file_helper.rb

Overview

Utility methods for safe file reading.

Class Method Summary collapse

Class Method Details

.ensure_readable!(path) ⇒ Object

Checks that path exists. Raises FileMissingError if not.

Raises:



7
8
9
# File 'lib/snippet_cli/file_helper.rb', line 7

def self.ensure_readable!(path)
  raise FileMissingError, "File not found: #{path}" unless File.exist?(path)
end

.read_or_empty(path) ⇒ Object

Returns the contents of path if it exists, or an empty string otherwise.



12
13
14
# File 'lib/snippet_cli/file_helper.rb', line 12

def self.read_or_empty(path)
  File.exist?(path) ? File.read(path) : ''
end