78
YAML has inheritance. The most clear example I have ever seen is here: http://blog.101ideas.cz/posts/dry-your-yaml-files.html
I need something more complex: I need to override object's object's property. Here is an example:
database: &default
server:
ip: 192.168.1.5
port: 2000
db_name: test
user:
name: root
password: root
# database foo differs from default by only its port and user password
foo_database:
<<: *default
server:
port: 2001
db_name: foo
user:
password: foo_root
I want to get this result:
foo_database.server.ip -> 192.168.1.5
foo_database.server.port -> 2001
foo_database.db_name -> foo
foo_database.user.name -> root
foo_database.user.password -> foo_root
But if you declare like this, you will get these properties incorrect (according to expected values):
foo_database.server.ip -> will be None
foo_database.user.name -> will be None
because new "server" object has only "port" property and it overrides whole old "server" object.
How do I get the kind of inheritance which I want to achieve?
Edit
Here is my exact intention with a working code in LiveScript:
config =
default:
ip: \192.168.1.5
port: 2000
name: \root
password: \root
db:
name: \default
location: \LA
foo-database:~ -> @default `merge` do
ip: \11.11.11.11
db:
name: \my-foo
bar-database:~ -> @foo-database `merge` do
password: \1234
db:
location: \SF
config.default
# => {"ip":"192.168.1.5","port":2000,"name":"r