Module: SnippetCli::FileHelper
- Defined in:
- lib/snippet_cli/file_helper.rb
Overview
Utility methods for safe file reading.
Class Method Summary collapse
-
.ensure_readable!(path) ⇒ Object
Checks that path exists.
-
.read_or_empty(path) ⇒ Object
Returns the contents of path if it exists, or an empty string otherwise.
Class Method Details
.ensure_readable!(path) ⇒ Object
Checks that path exists. Raises FileMissingError if not.
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 |