8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyプロジェクトのコンフィグ読み出しでChamberを使ってみた

Last updated at Posted at 2014-04-22

Settingslogicを使ってconfig.yml, config.local.yml運用してみる - Qiita の続編で、binarylogic/settingslogicからm5rk/chamberに乗り換え。

こうしたかった

  • 設定はYamlに書きたかった
  • CIやPaaS(Heroku)にフィットさせるため、環境変数と併用したかった
    • ChamberはSettingsLogicと同じように、Yamlを一度ERbで処理する
  • hoge.yml, hoge.local.ymlとあったら、hoge.local.ymlを優先するようにマージしたかった
    • ローカル作業時はわざわざ環境変数を変更するのが面倒なことが多い
    • test-kitchenの設定の持ち方を参考にした
    • hoge.ymlは基本的にERbのENVから取るので、センシティブな値を除去してリポジトリにADDできるのが嬉しい。

このように書いた

require 'chamber'

env_confs = [
  File.expand_path('../../config/environment.yml', __FILE__),
  File.expand_path('../../config/environment.local.yml', __FILE__)
]
EnvSettings = Chamber.load files: env_confs


app_confs = [
  File.expand_path('../../config/app.yml', __FILE__),
  File.expand_path('../../config/app.local.yml', __FILE__)
]
AppSettings = Chamber.load files: app_confs

まあまあスッキリした。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?