module Dotenv::Substitutions::Variable
Substitute variables in a value.
HOST=example.com URL="https://$HOST"
Constants
- VARIABLE
Public Class Methods
call(value, env, overwrite: false)
click to toggle source
# File lib/dotenv/substitutions/variable.rb, line 21 def call(value, env, overwrite: false) combined_env = overwrite ? ENV.to_h.merge(env) : env.merge(ENV) value.gsub(VARIABLE) do |variable| match = $LAST_MATCH_INFO substitute(match, variable, combined_env) end end
Private Class Methods
substitute(match, variable, env)
click to toggle source
# File lib/dotenv/substitutions/variable.rb, line 31 def substitute(match, variable, env) if match[1] == "\\" variable[1..] elsif match[3] env.fetch(match[3], "") else variable end end