自分用のConfigクラス

railsでどうすればいいのかわからなかったので、取り急ぎ作った。

require 'singleton'

module Bei
  class Config
    include Singleton

    def initialize
      file  = Rails.root.to_s + '/config/environments/config_' + ENV['RAILS_ENV'] + '.rb'
      @config = eval ( open(file).read )
    end

    def get(key)
      return Marshal::load(Marshal.dump(@config[key])) #deep clone
    end

  end 
end

config/environments/config_test.rb

{

  :twitter_consumer => {
    :key => 'foo',
    :secrete => 'bar'
  }
    
}  

使い方。

   config = Bei::Config.instance().get(:twitter_consumer)