Best way to open config files? #44

Closed
garethrees opened this Issue Oct 16, 2012 · 5 comments

Projects

None yet

4 participants

In my config/deploy.rb I have some configuration variables stored in a YAML file.

What's the best way to load this in? Currently I have:

CONFIG = YAML.load(File.open('config/deploy/deploy.yml'))

# >> File.open('config/deploy/deploy.yml')
# => #<File:config/deploy/deploy.yml>

This doesn't load a full path though, so I could do:

CONFIG = YAML.load(File.open(Rails.root.join('config/deploy', 'deploy.yml')))

# >> File.open(Rails.root.join('config/deploy', 'deploy.yml'))
# => #<File:/Users/gareth/Code/repo/config/deploy/deploy.yml>

Is there a "standard" way of doing this? What do you guys do?

Thanks

Contributor

You can use https://github.com/binarylogic/settingslogic Settings Logic gem. It provides nice interface for interaction with application configs.

Contributor

In Rails 4.2 (currently in beta) you'll be able to load yaml configs like this:

Rails::Application.config_for(:some_yaml)

http://weblog.rubyonrails.org/2014/8/20/Rails-4-2-beta1/

Owner
bbatsov commented Mar 8, 2015

@vestimir Guess we can mention this is the guide.

Contributor
vestimir commented Mar 8, 2015

I'll send a PR later today ;)

Fixed by #136 👍

@garethrees garethrees closed this Mar 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment