Class: Bolt::PAL::YamlPlan::Step::Eval
- Inherits:
-
Step
- Object
- Step
- Bolt::PAL::YamlPlan::Step::Eval
- Defined in:
- lib/bolt/pal/yaml_plan/step/eval.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#evaluate(scope, evaluator) ⇒ Object
Evaluates the step.
-
#transpile ⇒ Object
Transpiles the step into the plan language.
Class Method Details
.required_keys ⇒ Object
8 9 10 |
# File 'lib/bolt/pal/yaml_plan/step/eval.rb', line 8 def self.required_keys Set['eval'] end |
Instance Method Details
#evaluate(scope, evaluator) ⇒ Object
Evaluates the step
14 15 16 17 |
# File 'lib/bolt/pal/yaml_plan/step/eval.rb', line 14 def evaluate(scope, evaluator) evaluated = evaluator.evaluate_code_blocks(scope, body) evaluated['eval'] end |
#transpile ⇒ Object
Transpiles the step into the plan language
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bolt/pal/yaml_plan/step/eval.rb', line 21 def transpile code = String.new(" ") code << "$#{body['name']} = " if body['name'] code_body = Bolt::Util.to_code(body['eval']) || 'undef' # If we're trying to assign the result of a multi-line eval to a name # variable, we need to wrap it in `with()`. if body['name'] && code_body.lines.count > 1 indented = code_body.gsub(/\n/, "\n ").chomp(" ") code << "with() || {\n #{indented}}" else code << code_body end code << "\n" end |