Sha256: 7a9a1b62ba1af5f801a6f66c632c944ee3e383e61e773fd9d963297d3228e486

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

      shortcuts = steps.shortcuts

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

      Grumlin::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 << Grumlin::StepData.new(step.name, args: args, params: step.params) unless shortcut&.lazy?

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

        new_steps = call(Grumlin::Steps.from(step))
        result.concat(new_steps.configuration_steps, new_steps.steps)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grumlin-1.2.0 lib/grumlin/shortcuts_applyer.rb
grumlin-1.1.0 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.4 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.3 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.3.beta1 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.2 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.1 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc7 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc6 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc5 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc4 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc3 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc2 lib/grumlin/shortcuts_applyer.rb
grumlin-1.0.0.rc1 lib/grumlin/shortcuts_applyer.rb