Sha256: 6888ef42865dca9b8a3f76ff654d90a41b3a8bc987e75b7c5107d6cb28dcc51c

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Grumlin
  class ShortcutsApplyer
    class << self
      def call(steps)
        return steps if !steps.is_a?(Steps) || !steps.uses_shortcuts?

        shortcuts = steps.shortcuts

        steps = [
          *process_steps(steps.configuration_steps, shortcuts),
          *process_steps(steps.steps, shortcuts)
        ]

        Steps.new(shortcuts).tap do |processed_steps|
          steps.each do |step|
            processed_steps.add(step.name, args: step.args, params: step.params)
          end
        end
      end

      private

      def process_steps(steps, shortcuts) # rubocop:disable Metrics/AbcSize
        steps.each_with_object([]) do |step, result|
          args = step.args.map { |arg| call(arg) }

          shortcut = shortcuts[step.name]
          next result << StepData.new(step.name, args: args, params: step.params) unless shortcut&.lazy?

          t = shortcuts.__
          action = shortcut.apply(t, *args, **step.params)
          next if action.nil? || action == t # Shortcut did not add any steps

          new_steps = call(Steps.from(action))
          result.concat(new_steps.configuration_steps, new_steps.steps)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grumlin-0.22.5 lib/grumlin/shortcuts_applyer.rb
grumlin-0.22.4 lib/grumlin/shortcuts_applyer.rb
grumlin-0.22.3 lib/grumlin/shortcuts_applyer.rb
grumlin-0.22.2 lib/grumlin/shortcuts_applyer.rb
grumlin-0.22.1 lib/grumlin/shortcuts_applyer.rb
grumlin-0.22.0 lib/grumlin/shortcuts_applyer.rb
grumlin-0.21.1 lib/grumlin/shortcuts_applyer.rb
grumlin-0.21.0 lib/grumlin/shortcuts_applyer.rb
grumlin-0.20.2 lib/grumlin/shortcuts_applyer.rb
grumlin-0.20.1 lib/grumlin/shortcuts_applyer.rb
grumlin-0.20.0 lib/grumlin/shortcuts_applyer.rb