Module: Banalize::Parser::ShellVariables

Included in:
Banalize::Parser
Defined in:
lib/banalize/parser/variables.rb

Overview

Parse and detect all shell variables used in script. Set instance level accessor ‘variables`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#variablesObject

All variables used in shell script



26
27
28
# File 'lib/banalize/parser/variables.rb', line 26

def variables
  @variables
end

Instance Method Details

#shell_variablesArray

Parse and detect all shell variables used in script.

Returns:

  • (Array)


14
15
16
17
18
19
20
21
22
23
# File 'lib/banalize/parser/variables.rb', line 14

def shell_variables
  ln = code.grep(/\$\{?\w+\}?/).map(&:last).join " "

  vars = ln.scan(/\$\{?\w+\}?/)
  vars.map! { |x| x.gsub(/[${}]/,'') }
  vars.reject! { |x| x =~ /^\d$/}

  @variables = vars || []
  @variables.uniq!
end