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
- Host: GitHub
- URL: https://github.com/dannyben/extended_yaml
- Owner: DannyBen
- License: mit
- Created: 2019-10-25T12:37:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-08-01T15:28:35.000Z (11 months ago)
- Last Synced: 2025-08-09T20:29:50.247Z (11 months ago)
- Topics: yaml
- Language: Ruby
- Size: 32.2 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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