Module: Pandocomatic::PandocomaticYAML
- Defined in:
- lib/pandocomatic/pandocomatic_yaml.rb
Overview
PandocomaticYAML is a wrapper around ruby’s YAML library that replaces occurrences of “$(X)$” in the YAML by the value of the evironment variable
-
If variable X cannot be found, an exception is thrown.
Constant Summary collapse
- PERMITTED_YAML_CLASSES =
List of classes that are permitted in YAML
[Date].freeze
- VAR_PATTERN =
Regular expression representing environment variables in templates
/\$\((?<var>[a-zA-Z_][a-zA-Z0-9_]*)\)\$/
Class Method Summary collapse
-
.load(str, path = nil) ⇒ Hash
Load a string, substitute any variables, and parse as YAML.
-
.load_file(path) ⇒ Hash
Load a text file, substitute any variables, and parse as YAML.
Class Method Details
.load(str, path = nil) ⇒ Hash
Load a string, substitute any variables, and parse as YAML.
43 44 45 |
# File 'lib/pandocomatic/pandocomatic_yaml.rb', line 43 def self.load(str, path = nil) YAML.safe_load substitute_variables(str, path), permitted_classes: PERMITTED_YAML_CLASSES end |
.load_file(path) ⇒ Hash
Load a text file, substitute any variables, and parse as YAML.
52 53 54 |
# File 'lib/pandocomatic/pandocomatic_yaml.rb', line 52 def self.load_file(path) self.load File.read(path), path end |