Module: ExpandVariables

Defined in:
lib/expand_variables.rb

Constant Summary collapse

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) ⇒ Object



7
8
9
10
11
# File 'lib/expand_variables.rb', line 7

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

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



13
14
15
16
17
# File 'lib/expand_variables.rb', line 13

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

.possible_var_reference?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

def possible_var_reference?(value)
  return unless value

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