laserlemon / figaro

Simple Rails app configuration
MIT License
3.77k stars 288 forks source link

Ability to configure Figaro to use a more readable name. #216

Open dedman opened 9 years ago

dedman commented 9 years ago

Is it just me or is the following not very readable?

Figaro.env.stripe_api_key

As compared to something like

config.stripe_api_key

I think it would be nice if Figaro had an easy way to change the name or method of accessing the env variables. You can't just do

config = Figaro.env

So as a workaround you can do something like this in the config/initializers/figaro.rb

#Rename Figaro to be something meaningful.
module Config
  extend self

  def respond_to?(method, *)
    Figaro::ENV.respond_to?(method)
  end

  private
    def method_missing(method, *)
      Figaro::ENV.send(method)
    end
end

#Now you can access the value via
Config.stripe_api_key

Is this the best/easiest way to have a nice readable way to access the env variables?

phillipoertel commented 8 years ago

I built the same, +1 to have this built in.