2014-04-10 9 views
0

내 응용 프로그램에 대한 단일 구성 지점을 갖기 위해서는 유효한 루비 코드 인 YAML 구성 파일을 만들어야합니다. 나는. YAML로 구문 분석되고 루비로 구문 분석 될 수있는 혼합 구문 파일.유효한 루비 구문과 유효한 YAML 구문 모두를 작성하는 방법

내 응용 프로그램은 god 보석으로 관리되는 일련의 프로세스입니다. 새로운 구성 파일마다 새로운 유지 보수 프로세스 (시계) 그룹을로드하려고합니다.

신은 정의 된 새로운 시계로 새로운 app.god (ruby) 파일을로드하는 것을 허용하지만 app.god 및 app.yml은 하나의 파일을 원하지 않습니다. 가장 단순한 것은 app.god 파일을 포함하고 그 안에 구성을 포함하는 것일 수도 있지만 유효한 루비 코드였던 yml 파일의 아이디어를 선호했습니다.

답변

0
#I found this that might be helpful: 
#This is a valid ruby and a valid YAML file 
#Comments are the same in YAML and ruby 

true ?true: 
- <<YAML.to_i 
# At this point in ruby it is the contents of a here doc (that will be 
# converted to an integer and negated if true happens not to be true) 
# In YAML it is a hash with the first entry having key "true ?true" 
# representing a list containing the string "- <<YAML.to_i" 
# If your YAML object should be a list not a hash you could remove the first line 

any_valid_yaml: from here 
a_list: 
- or 
- anything 
- really 
#Then mark the end of the YAML document with 
--- 
#And YAML is done and ignores anything from here on 
#Next terminate the ruby here document 
YAML 

#Now we're in ruby world 

@this = "pure ruby" 

def anything(ruby) 
    "here" 
end