Module: ExpandVariables

Defined in:
lib/expand_variables.rb

Constant Summary collapse

VariableExpansionError =
Class.new(StandardError)
VARIABLES_REGEXP =
/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/

Class Method Summary collapse

Class Method Details

.expand(value, variables, expand_file_refs: true, fail_on_masked: false) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/expand_variables.rb', line 9

def expand(value, variables, expand_file_refs: true, fail_on_masked: false)
  replace_with(value, variables) do |collection, last_match|
    match_or_blank_value(
      collection, last_match, expand_file_refs: expand_file_refs, fail_on_masked: fail_on_masked
    )
  end
end

.expand_existing(value, variables, expand_file_refs: true, fail_on_masked: false) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/expand_variables.rb', line 17

def expand_existing(value, variables, expand_file_refs: true, fail_on_masked: false)
  replace_with(value, variables) do |collection, last_match|
    match_or_original_value(
      collection, last_match, expand_file_refs: expand_file_refs, fail_on_masked: fail_on_masked
    )
  end
end

.possible_var_reference?(value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/expand_variables.rb', line 25

def possible_var_reference?(value)
  return unless value

  %w[$ %].any? { |symbol| value.include?(symbol) }
end