Skip to content

Ruby YAML with support for including and merging additional YAML files

License

Notifications You must be signed in to change notification settings

DannyBen/extended_yaml

Repository files navigation

Extended YAML

Gem Version Build Status Maintainability


ExtendedYAML adds a couple of additional features to the standard YAML library:

  1. Each YAML file can extend (inherit from) other YAML files by specifying extends: other_file
  2. 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: 80

which uses extends to load this subdir/production.yml file.

settings:
  host: example.com

We 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

  1. Arrays will be merged.
  2. Nested hashes will be merged.
  3. Other types of values will be overridden based on which loaded file was the last to define them.
  4. ERB tags will be evaluated in all YAML files.
  5. The extends option can use either a single file string, or an array. Extensions are optional.
  6. Using * anywhere in the extends path will load multiple files with one call.
  7. If you need to use a key that is named differently than extends, provide it using the key keyword argument:
    ExtendedYAML.load 'examples/simple.yml', key: 'include'

See the examples/master.yml file for additional information.

About

Ruby YAML with support for including and merging additional YAML files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages