I'm working on a gem
and there I need to create a file like database.yml
. I'm creating Yaml file but something not happening good . Below is my code
Key value pairs
STATUS_VALUES =[
{
'default' => {
'defaults' =>
{
'adapter' => 'pasql',
'encoding'=> 'utf8',
'database'=> 'mysql',
'username'=> 'root',
'password'=> nil
}
}
},
{
'development' =>
{
'{{<<}}' => '*default'
}
}
]
data = STATUS_VALUES
File.open(file, 'w') { |f| YAML.dump(data.to_yaml, f) }
My Expected output
- default: &defaults
adapter: pasql
encoding: utf8
database: mysql
username: root
password:
- development:
<<: *default
My actual output
- default:
adapter: pasql
encoding: utf8
database: mysql
username: root
password: ''
- development:
!!str '<<': "*default"
To be clear I have three differences here
- first line i.e default , i want it to be default: &defaults
- second password needs to be without any value
- last line
!!str '<<': "*default"
needed to be<<: *default
Any help will be greatly appreciating - Have a good day - thanks