bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use ERB in env file?

benlieb opened this issue · comments

Is there any way to parse this first with ERB (using Rails)?

Similar to how yml files work:

  url: <%= ApplicationConfig.defaults("REDIS_URL") %>
  channel_prefix: threadable_api_production

i've been using yml files with config_for(:the_thing) to get the ENV files into rails

# config/the_thing.yml
shared:
  base_url: <%= ENV["BASE_URL"] %>
  admin_password: <%= ENV["ADMIN_PASSWORD"] %>

does this get you what you need? rather than trying to run ruby and interpolate in the .env file

@gcentauri I referenced yml files in my question…

@benlieb there is not erb+yaml support built into dotenv, but you could pretty easily load the file yourself:

Dotenv.update YAML.load(ERB.new(Dotenv::Rails.root.join('.env.yml').read).result)