Is there a custom tag in YAML for ruby to include a YAML file inside a YAML file?
#E.g.:
--- !include
filename: another.yml
A similar question was asked some time ago and there was no relevant answer.
I am wondering if there is some custom tag for Ruby similar to this one for Python.
YAML is a digestible data serialization language often used to create configuration files with any programming language. Designed for human interaction, YAML is a strict superset of JSON, another data serialization language. But because it's a strict superset, it can do everything that JSON can and more.
If you are in Rails, YAML can include ERB.
Combine that together, and here is how you can use <%= %>
to include one file from another:
database.yml
<% if File.exists?('/tmp/mysql.sock') %>
<%= IO.read('config/database.mysql.yml') %>
<% else %>
<%= IO.read('config/database.sqlite.yml') %>
<% end %>
database.sqlite.yml
sqlite: &defaults
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *defaults
database: db/development.sqlite3
test:
<<: *defaults
database: db/test.sqlite3
production:
<<: *defaults
database: db/production.sqlite3
database.mysql.yml
development:
adapter: mysql2
# ... the rest of your mysql configuration ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With