Extended YAML
ExtendedYAML adds a couple of additional features to the standard YAML library:
- Each YAML file can extend (inherit from) other YAML files by specifying
extends: other_file - YAML files are parsed for ERB tags.
It is a simpler reimplementation of yaml_extend.
Installation
$ gem install extended_yaml
Usage
Given this simple.yml file:
extends: subdir/production.yml
settings:
host: localhost
port: 80which uses extends to load this
subdir/production.yml file.
settings:
host: example.comWe can now load the extended YAML file like this:
# Load an extended YAML
require 'extended_yaml'
p ExtendedYAML.load 'examples/simple.yml'
#=> {"settings"=>{"host"=>"localhost", "port"=>80}}Notes
- Arrays will be merged.
- Nested hashes will be merged.
- Other types of values will be overridden based on which loaded file was the last to define them.
- ERB tags will be evaluated in all YAML files.
- The
extendsoption can use either a single file string, or an array. Extensions are optional. - Using
*anywhere in theextendspath will load multiple files with one call. - If you need to use a key that is named differently than
extends, provide it using thekeykeyword argument:ExtendedYAML.load 'examples/simple.yml', key: 'include'
See the examples/master.yml file for additional information.