Carregando e gerando arquivo Yaml com chaves semelhantes

Eu tenho um documento de arquivo yaml que tem chaves semelhantes: -

sample_file.yml

line:
  title: line-name
  department: transcription

  input_formats:
    - input_format:
        name: company
        required: true
        valid_type: general
    - input_format:
        name: website
        required: false
        valid_type: url

Depois de gerar new_file.yml as chaves são classificadas em ordem alfabética: -

new_file.yml

line: 
  department: transcription
  input_formats: 
    - 
      input_format: 
      name: company
      required: true
      valid_type: general
    - 
      input_format: 
      name: website
      required: false
      valid_type: url

  title: line-name

o código para abrir sample_file e criar new_file está abaixo: -

require 'yaml'
require 'ya2yaml'


@file = YAML::load(File.open("/Users/manish/Desktop/yaml/sample_file.yml"))
@new_file = File.new("/Users/manish/Desktop/yaml/new_file.yml", "w+") 
@new_file.syswrite(@file.ya2yaml(:hash_order => ['title','department','input_formats']))

Estou usando a gem "ya2yaml" para gerar o arquivo yaml. A fim de obter a mesma ordem que está em sample_file.yml, usei hash_order aqui (oculto) => ['title', 'department', 'input_formats'])) , mas não está funcionando. Como posso manter o pedido?

9
задан Andrew Grimm 17 June 2011 в 06:26
поделиться