figaro icon indicating copy to clipboard operation
figaro copied to clipboard

Ability to configure Figaro to use a more readable name.

Open dedman opened this issue 8 years ago • 1 comments

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?

dedman avatar Oct 06 '15 15:10 dedman

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

phillipoertel avatar Apr 25 '16 08:04 phillipoertel