我正在尝试使用YAML创建应用程序中使用的所有存储过程的列表以及从中调用它们的位置.我设想了类似下面的内容,但我认为YAML不允许多级嵌套.
access_log:
stored_proc: getsomething
uses:
usedin: some->bread->crumb
usedin: something else here
stored_proc: anothersp
uses:
usedin: blahblah
reporting:
stored_proc: reportingsp
uses:
usedin: breadcrumb
Run Code Online (Sandbox Code Playgroud)
有没有办法在YAML中做到这一点,如果没有,还有哪些其他选择?
Ili*_*ion 15
这正是我在YAML中使用嵌套级别来获取perl脚本的配置文件的方法.对于如何在Ruby中处理所需结构,本YAML教程可能是一个很好的参考.
我认为你的问题是尝试混合类型.我建议修改如下:
reporting:
stored_procs:
reportingsp
uses:
usedin: breadcrumb
secondProc
uses:
usedin: something_else
Run Code Online (Sandbox Code Playgroud)
Phr*_*ogz 15
正如@Ilion所指出的,你不能拥有指向字符串和对象的属性; 你需要一个数组,或给你的stored_proc名称一个标签.此外,当你真正想要的是一个数组时,你使用相同的名称继续在你的键上运行.这是一个简单的例子,证明它有效:
MY_YAML = "
access_log:
-
name: getsomething
uses:
- some->bread
- something else here
-
name: anothersp
uses:
- blahblah"
require 'yaml'
require 'pp'
pp YAML.load(MY_YAML)
#=> {"access_log"=>[
#=> {"name"=>"get something", "uses"=>["some->bread", "something else here"]},
#=> {"name"=>"anothersp", "uses"=>["blahblah"]}
#=> ]}
Run Code Online (Sandbox Code Playgroud)