Sha256: 376437655479774f251def8b43ae472bd7a290af43974ed2568bcbe6769456ba

Contents?: true

Size: 1.08 KB

Versions: 39

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Bolt
  class PAL
    class YamlPlan
      class Step
        class Eval < Step
          def self.required_keys
            Set['eval']
          end

          # Evaluates the step
          #
          def evaluate(scope, evaluator)
            evaluated = evaluator.evaluate_code_blocks(scope, body)
            evaluated['eval']
          end

          # Transpiles the step into the plan language
          #
          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
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bolt-4.0.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.29.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.28.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.27.4 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.27.2 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.27.1 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.26.2 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.26.1 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.25.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.24.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.23.1 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.23.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.22.1 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.22.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.21.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.20.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.19.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.18.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.17.0 lib/bolt/pal/yaml_plan/step/eval.rb
bolt-3.16.1 lib/bolt/pal/yaml_plan/step/eval.rb