lib/grumlin/shortcuts_applyer.rb in grumlin-0.18.1 vs lib/grumlin/shortcuts_applyer.rb in grumlin-0.19.0
- old
+ new
@@ -2,46 +2,42 @@
module Grumlin
class ShortcutsApplyer
class << self
def call(steps)
- new.call(steps)
- end
- end
+ return steps unless steps.uses_shortcuts?
- def call(steps)
- return steps unless steps.uses_shortcuts?
+ shortcuts = steps.shortcuts
- shortcuts = steps.shortcuts
+ configuration_steps = process_steps(steps.configuration_steps, shortcuts)
+ regular_steps = process_steps(steps.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, args: step.args, params: step.params)
+ Steps.new(shortcuts).tap do |processed_steps|
+ (configuration_steps + regular_steps).each do |step|
+ processed_steps.add(step.name, args: step.args, params: step.params)
+ end
end
end
- end
- private
+ private
- def process_steps(steps, shortcuts) # rubocop:disable Metrics/AbcSize
- steps.each_with_object([]) do |step, result|
- args = step.args.map do |arg|
- arg.is_a?(Steps) ? ShortcutsApplyer.call(arg) : arg
- end
+ def process_steps(steps, shortcuts) # rubocop:disable Metrics/AbcSize
+ steps.each_with_object([]) do |step, result|
+ args = step.args.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, *args, **step.params)
- next if action.nil? || action == t # Shortcut did not add any steps
+ if shortcuts.include?(step.name)
+ t = TraversalStart.new(shortcuts)
+ action = shortcuts[step.name].apply(t, *args, **step.params)
+ 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, args: args, params: step.params)
+ new_steps = ShortcutsApplyer.call(Steps.from(action))
+ result.concat(new_steps.configuration_steps)
+ result.concat(new_steps.steps)
+ else
+ result << StepData.new(step.name, args: args, params: step.params)
+ end
end
end
end
end
end