Class: Bolt::PAL::YamlPlan::Step::Eval
- Inherits:
-
Bolt::PAL::YamlPlan::Step
- Object
- Bolt::PAL::YamlPlan::Step
- Bolt::PAL::YamlPlan::Step::Eval
- Defined in:
- lib/bolt/pal/yaml_plan/step/eval.rb
Constant Summary
Constants inherited from Bolt::PAL::YamlPlan::Step
Instance Attribute Summary
Attributes inherited from Bolt::PAL::YamlPlan::Step
Class Method Summary collapse
Instance Method Summary collapse
-
#evaluate(scope, evaluator) ⇒ Object
Evaluates the step.
-
#transpile ⇒ Object
Transpiles the step into the plan language.
Methods inherited from Bolt::PAL::YamlPlan::Step
allowed_keys, create, #initialize, option_keys, parse_code_string, validate, validate_puppet_code, validate_step_keys
Constructor Details
This class inherits a constructor from Bolt::PAL::YamlPlan::Step
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 |