17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/bolt/pal/yaml_plan/transpiler.rb', line 17
def transpile(relative_path)
@plan_path = File.expand_path(relative_path)
@modulename = Bolt::Util.module_name(@plan_path)
@filename = @plan_path.split(File::SEPARATOR)[-1]
validate_path
plan_object = parse_plan
plan_string = String.new("# WARNING: This is an autogenerated plan. " \
"It may not behave as expected.\n" \
"plan #{plan_object.name}(")
plan_object.parameters&.each_with_index do |param, i|
plan_string << param.transpile
last = i + 1 == plan_object.parameters.length ? "\n" : ","
plan_string << last
end
plan_string << ") {\n"
plan_object.steps&.each do |step|
plan_string << step.transpile
end
plan_string << "\n return #{Bolt::Util.to_code(plan_object.return)}\n" if plan_object.return
plan_string << "}"
puts plan_string
validate_plan(plan_string)
plan_string
end
|