Module: VagrantVbguest::Helpers::OsRelease::Substitutions::Variable

Defined in:
lib/vagrant-vbguest/helpers/os_release.rb

Overview

Substitute variables in a value.

HOST=example.com
URL="https://$HOST"

Constant Summary collapse

VARIABLE =
/
  (\\)?         # is it escaped with a backslash?
  (\$)          # literal $
  (?!\()        # shouldnt be followed by paranthesis
  (\{)?         # allow brace wrapping
  ([A-Z0-9_]+)? # optional alpha nums
  (\})?         # closing brace
/xi

Class Method Summary collapse

Class Method Details

.call(value, env) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vagrant-vbguest/helpers/os_release.rb', line 73

def call(value, env)
  value.gsub(VARIABLE) do |variable|
    match = $LAST_MATCH_INFO

    if match[1] == '\\'
      variable[1..-1]
    elsif match[4]
      env.fetch(match[4]) { match[2..5].join }
    else
      variable
    end
  end
end