Sha256: c3160d556957da0ab7780b54a4a62e6af05894cde675c95cdb7a0fd0def1c9aa
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true module Grumlin class ShortcutsApplyer class << self def call(steps) new.call(steps) end end def call(steps) return steps unless steps.uses_shortcuts? shortcuts = steps.shortcuts configuration_steps = process_steps(steps.configuration_steps, shortcuts) regular_steps = process_steps(steps.steps, shortcuts) Steps.new(shortcuts).tap do |processed_steps| (configuration_steps + regular_steps).each do |step| processed_steps.add(step.name, step.arguments) end end end private def process_steps(steps, shortcuts) # rubocop:disable Metrics/AbcSize steps.each_with_object([]) do |step, result| arguments = step.arguments.map do |arg| arg.is_a?(Steps) ? ShortcutsApplyer.call(arg) : arg end if shortcuts.include?(step.name) t = TraversalStart.new(shortcuts) action = shortcuts[step.name].apply(t, *arguments) next if action.nil? || action == t # Shortcut did not add any steps new_steps = ShortcutsApplyer.call(Steps.from(action)) result.concat(new_steps.configuration_steps) result.concat(new_steps.steps) else result << StepData.new(step.name, arguments) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
grumlin-0.17.0 | lib/grumlin/shortcuts_applyer.rb |
grumlin-0.16.1 | lib/grumlin/shortcuts_applyer.rb |
grumlin-0.16.0 | lib/grumlin/shortcuts_applyer.rb |