在这个database.yml文件中,&,<< * *是什么意思? [英] What do the &,<<, * mean in this database.yml file?
问题描述
到目前为止,我只使用了database.yml与每个参数调用明确,在下面的文件它使用一些字符我不明白。每行和符号(&,*,<<)是什么意思,我如何读取此文件?
开发:& default
adapter:postgresql
database:dev_development
test:& test
<< ;: * default
database:test_test
cucumber:
<< ;: * test
production:
<< ;: * default
数据库:test_production
; 标记节点的别名(在您的示例中
& default
将开发节点别名为default)和 *
引用名为default的别名节点。 < <:
插入该节点的内容。
允许我引用YAML规格:
重复节点(对象)首先由锚点标记(用&符号&标记),然后再别名
test:& test
<< ;: * default
$ b b
实际上扩展到
test:& test
adapter:postgresql#from default别名
数据库:dev_development#从默认别名
同时使测试节点以及在别名测试下可用。
查看 YAML规范 - 2.2结构的详细信息(或者如果您还需要moar docs ++: 3.2.2.2。锚点和别名)Up until now I have only used database.yml with each parameter called out explicitly, in the file below it uses some characters I do not understand. What does each line and symbol(&,*,<<) mean, how do i read this file?
development: &default adapter: postgresql database: dev_development test: &test <<: *default database: test_test cucumber: <<: *test production: <<: *default database: test_production
解决方案The
&
marks an alias for the node (in your example&default
aliases the development node as "default") and the*
references the aliased node with the name "default". The<<:
inserts the content of that node.Allow me to quote the YAML spec here:
Repeated nodes (objects) are first identified by an anchor (marked with the ampersand - "&"), and are then aliased (referenced with an asterisk - "*") thereafter.
so parts of your example
test: &test <<: *default
actually expand to
test: &test adapter: postgresql # from the "default" alias database: dev_development # from the "default" alias
and at the same time make the "test" node as well available under the alias "test". have a look at the YAML specification - 2.2 Structures for further details (or if you need even moar docs++: 3.2.2.2. Anchors and Aliases)
这篇关于在这个database.yml文件中,&,<< * *是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!