I saw this railscast on application wide configs and I liked it alot, however, I am not big on typing APP_CONFIG[:value][:subvalue] so I have made a small tweak to that, and placed it as a model, which is where I like it to be, as it is a model of the applications configuration, where the datasource is a fixed file, in this case, config/config.yml.

I suppose, you could put it anywhere you like.

class ValueProxy
  def initialize(attrs)
    @attrs = attrs
  end
  def method_missing(sym,*args,&block)
    sym = sym.to_s
    if @attrs[sym] then
      if @attrs[sym].class == Hash then
        return ValueProxy.new(@attrs[sym])
      else
        return @attrs[sym]
      end
    end
  end
end
class AppConfig
  @@config = YAML::load_file("#{RAILS_ROOT}/config/config.yml")
  def self.method_missing(sym, *args, &block)
    if @@config[sym.to_s] then
      if @@config[sym.to_s].class == Hash then
        return ValueProxy.new(@@config[sym.to_s])
      else
        return @@config[sym.to_s]
      end
    end
  end
  def self.respond_to?(sym,include_private=false)
    true
  end
end

Here is the yml file:

auth:
  http_basic: true

And then the usage:

AppConfig.auth.http_basic == true

Well that’s more or less it.