laserlemon / figaro

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

Is there a way to alias ENV key names? #251

Closed mpoisot closed 7 years ago

mpoisot commented 7 years ago

I'm setting up an app for Heroku that's using the Redis Cloud addon. Redis Cloud manages sets REDISCLOUD_URL in the heroku app's config.

So I went about using ENV['REDISCLOUD_URL'] in several places in my code, but found myself wishing I could rename it. The name is misleading (we don't use Redis Cloud in development), and if I ever change providers it would be even more confusing (so I'd have to update the string in a bunch of files).

I'd love to do something like this in application.yml:

redis_url: ENV[REDISCLOUD_URL] || "redis://localhost:6379/1"

I realize that's not valid YAML. Is there a way to do that in the figaro initializer?

laserlemon commented 7 years ago

Try adding ERB to your YAML:

redis_url: <%= ENV["REDISCLOUD_URL"] || "redis://localhost:6379/1" %>

Hope that helps!