English 中文(简体)
运输和生产 Yaml 具有类似钥匙的档案
原标题:Loading and generating Yaml file with similar keys

I ve got a yaml file document which have similar keys :-

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

在编造新档案之后。 key 钥匙按字母顺序分类:

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

开放式样本-档案和制作新档案的代码如下:

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 ]))

I m using "ya2yaml" gem for generating yaml file. In order to get the same order as it s in sample_file.yml i ve used hash_order here @new_file.syswrite(@file.ya2yaml(:hash_order => [ title , department , input_formats ])), but it s not working. How can i retain the order?

最佳回答

Finally i got the solution of the ordering issue.

The :hash_order only work for top level hash.
so it works only when i remove "line" key from my sample_file.yml. Then the order is preserved. :-

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
问题回答

您能否改变阿盟档案的格式? 你们的《马列》档案中专门有一只带有重复钥匙的散射。 这是无。

如果有的话,阿盟档案也使用一个清单。

line:
    title: line-name
    department: transcription

    formats:
        - input_format:
          name: company
          required: true
          valid_type: general

        - input_format:
          name: website
          required: false
          valid_type: url
....

这些额外的 da子将解决你的问题。

YAML意在储存关键价值乳制品,因此其定购单对YA马尤其重要。

</em>解决你的问题,是用1.9.2鲁比语解决的,这符合在海螺中插入顺序(在Rub.1.8.7中是一例)。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签