Module: SnippetCli::YamlLoader
- Defined in:
- lib/snippet_cli/yaml_loader.rb
Overview
Shared YAML file loading with existence check and syntax-error handling.
Class Method Summary collapse
-
.load(path, permitted_classes: [Symbol]) ⇒ Object
Loads and parses a YAML file.
Class Method Details
.load(path, permitted_classes: [Symbol]) ⇒ Object
Loads and parses a YAML file. Raises FileMissingError if the file does not exist. Raises InvalidYamlError if the file contains invalid YAML syntax.
12 13 14 15 16 17 |
# File 'lib/snippet_cli/yaml_loader.rb', line 12 def self.load(path, permitted_classes: [Symbol]) FileHelper.ensure_readable!(path) YAML.safe_load_file(path, permitted_classes: permitted_classes) || {} rescue Psych::SyntaxError => e raise InvalidYamlError, "Invalid YAML: #{e.}" end |