An open API service indexing awesome lists of open source software.

https://github.com/dannyben/extended_yaml

Ruby YAML with support for including and merging additional YAML files
https://github.com/dannyben/extended_yaml

yaml

Last synced: 9 months ago
JSON representation

Ruby YAML with support for including and merging additional YAML files

Awesome Lists containing this project

README

          

Extended YAML
==================================================

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][1].

Installation
--------------------------------------------------

$ gem install extended_yaml

Usage
--------------------------------------------------

Given this [simple.yml](examples/simple.yml) file:

```yaml
extends: subdir/production.yml

settings:
host: localhost
port: 80
```

which uses `extends` to load this
[subdir/production.yml](examples/subdir/production.yml) file.

```yaml
settings:
host: example.com
```

We can now load the extended YAML file like this:

```ruby
# 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:
```ruby
ExtendedYAML.load 'examples/simple.yml', key: 'include'
```

See the [examples/master.yml](examples/master.yml) file for additional
information.

[1]: https://github.com/magynhard/yaml_extend