Module: Dotenv::Substitutions::Variable
- Defined in:
- lib/dotenv/substitutions/variable.rb
Overview
Substitute variables in a value.
HOST=example.com
URL="https://$HOST"
Constant Summary collapse
- VARIABLE =
/ (\\)? # is it escaped with a backslash? (\$) # literal $ \{? # allow brace wrapping ([A-Z0-9_]+) # match the variable \}? # closing brace /xi
Class Method Summary collapse
Class Method Details
.call(value, env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dotenv/substitutions/variable.rb', line 20 def call(value, env) value.gsub(VARIABLE) do |variable| match = $LAST_MATCH_INFO if match[1] == '\\' variable[1..-1] else env.fetch(match[3]) { ENV[match[3]] } end end end |