Module: ScriptLocator

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

Instance Method Summary collapse

Instance Method Details

#errorsObject



9
10
11
# File 'lib/script_executor/script_locator.rb', line 9

def errors
  @errors ||= []
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/script_executor/script_locator.rb', line 27

def evaluate_script_body(content, env, type=:erb)
  content = content.join("\n") if content.kind_of? Array

  case type
    when :erb
      template = ERB.new content
      template.result(env).strip
    else
      interpolator = TextInterpolator.new

      result = interpolator.interpolate content, env

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

        @errors = interpolator.errors
      end

      result
  end
end

#scripts(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/script_executor/script_locator.rb', line 13

def scripts(file)
  data = extract_data file

  begin
    scripts_parser = ScriptsParser.new
    parsed_content = scripts_parser.parse data

    transformer = ScriptsTransform.new
    transformer.transform(parsed_content)
  rescue Parslet::ParseFailed => failure
    puts failure.cause.ascii_tree
  end
end