Module: ScriptLocator

Included in:
BaseProvision, ScriptExecutor
Defined in:
lib/script_executor/script_locator.rb

Instance Method Summary collapse

Instance Method Details

#evaluate_script_body(content, env, type = :erb) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/script_executor/script_locator.rb', line 12

def evaluate_script_body content, env, type=:erb
  case type
    when :erb
      template = ERB.new content
      template.result(env).strip

    when :string
      interpolator = TextInterpolator.new

      result = interpolator.interpolate content, env

      puts interpolator.errors if interpolator.errors.size > 0

      result
    else
      interpolator = TextInterpolator.new

      result = interpolator.interpolate content, env

      puts interpolator.errors if interpolator.errors.size > 0

      result
  end
end

#script_title(script) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/script_executor/script_locator.rb', line 37

def script_title script
  if script[0] == '#'
    StringIO.new(script[1..-1]).readline.strip
  else
    nil
  end
end

#scripts(file) ⇒ Object



6
7
8
9
10
# File 'lib/script_executor/script_locator.rb', line 6

def scripts file
  data = extract_data file

  locate_scripts(data)
end