bkeepers / envy

a schema for your application's environment variables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variable substitution for default values

laserlemon opened this issue · comments

From the README:

desc "The host name where the API is served from."
string :api_host_name, :default => "api.$HOST_NAME"

The api.$HOST_NAME notation wasn't immediately obvious to me. I'm assuming that this notation makes sense in the context of Bash scripting but maybe it's worth considering a more Ruby-centric approach:

desc "The host name where the API is served from."
string :api_host_name, :default => "api.%{host_name}"

a la Ruby's String#% method.

This might be easier for the user to manage as well since it depends on the Envy names that you define rather than the underlying ENV variable names (since they may not always coincide).

I actually removed this from the readme in #11. This was from some README-driven development that I did for bkeepers/dotenv#131. I think that style would make more sense if this was part of dotenv, since it already supports bash-style substitution, but definitely makes less sense now.

I would be up for the String#% version, or just telling people to put it inside of a block if they want to reference other configs.

For now you can use a lambda and ruby string interpolation:

string :app_host
string :api_host_name, default: -> { "api.#{app_host}" }