エンジニアのソフトウェア的愛情

または私は如何にして心配するのを止めてプログラムを・愛する・ようになったか

Config


Gemfile

gem 'config'


install

$ be rails g config:install
      create  config/initializers/config.rb
      create  config/settings.yml
      create  config/settings.local.yml
      create  config/settings
      create  config/settings/development.yml
      create  config/settings/production.yml
      create  config/settings/test.yml
      append  .gitignore


config/settings.yml

format: 'Hello, %s!'


config/settings/development.yml

world: 'development world'


config/settings/test.yml

world: 'test world'


config/settings/production.yml

world: 'production world'
$ bundle exec rails r 'puts Settings.format % Settings.world'
Hello, development world!
$ RAILS_ENV=development bundle exec rails r 'puts Settings.format % Settings.world'
Hello, development world!
$ RAILS_ENV=test bundle exec rails r 'puts Settings.format % Settings.world'
Hello, test world!
$ RAILS_ENV=production bundle exec rails r 'puts Settings.format % Settings.world'
Hello, production world!