3

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

  1. first line i.e default , i want it to be default: &defaults
  2. second password needs to be without any value
  3. last line !!str '<<': "*default" needed to be <<: *default

Any help will be greatly appreciating - Have a good day - thanks

Mani
  • 2,391
  • 5
  • 37
  • 81
  • 1
    Possible duplicate of [Read and write YAML files without destroying anchors and aliases](http://stackoverflow.com/questions/13583588/read-and-write-yaml-files-without-destroying-anchors-and-aliases) – SoAwesomeMan Jul 02 '16 at 07:14

0 Answers0