开发者

How to use a yml file in my plugin?

开发者 https://www.devze.com 2023-01-18 04:21 出处:网络
Lets say my file lives in the config folder and it\'s 开发者_开发问答called config/foo.yml. I want to write in that file something like this:

Lets say my file lives in the config folder and it's 开发者_开发问答called config/foo.yml. I want to write in that file something like this:

development:
  status: developing
  foo: dev-bar

production:
  status: on-air
  foo: prod-bar

And then, I want my plugin to read this file and take the correct configuration values according to the environment the app is running in that very time.

What is the best way to achieve this?


Use YAML#load_file:

options = YAML.load_file('options.yml')
#=> { :development => { :status => 'developing', :foo => 'dev-bar' }, :production => { ... } 
0

精彩评论

暂无评论...
验证码 换一张
取 消