bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.
MIT License
6.61k stars 505 forks source link

Use ERB in env file? #501

Closed benlieb closed 6 months ago

benlieb commented 7 months ago

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
gcentauri commented 6 months ago

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

benlieb commented 6 months ago

@gcentauri I referenced yml files in my question…

bkeepers commented 6 months ago

@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)