How to include a YAML file inside a YAML file in Ruby

后端 未结 7 1420
悲&欢浪女
悲&欢浪女 2020-12-28 16:13

Is there a custom tag in YAML for ruby to include a YAML file inside a YAML file?

#E.g.:  
--- !include
filename: another.yml

A similar que

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-28 17:09

    I'm using this:

    load_config.rb (initializer)

    cf_1 = YAML::load(File.read("/etc/my_app/config.yml"))
    cf_2 = YAML::load(File.read(File.join(Rails.root, "config", "config.yml")))
    CONFIG = cf_1.merge(cf_2)
    

    Later, you can access config values by doing:

    CONFIG['value']
    

提交回复
热议问题