class ForemanMaintain::Runner

Class responsible for running the scenario

Public Class Methods

new(reporter, scenarios, options = {}) click to toggle source
# File lib/foreman_maintain/runner.rb, line 5
def initialize(reporter, scenarios, options = {})
  options.validate_options!(:assumeyes)
  @assumeyes = options.fetch(:assumeyes, false)
  @reporter = reporter
  @scenarios = Array(scenarios)
  @scenarios_with_dependencies = scenarios_with_dependencies
  @quit = false
end

Public Instance Methods

add_steps(*steps) click to toggle source
# File lib/foreman_maintain/runner.rb, line 47
def add_steps(*steps)
  # we we add the steps at the beginning, but still keeping the
  # order of steps passed in the arguments
  steps.reverse.each do |step|
    @steps_to_run.unshift(step)
  end
end
ask_to_quit(_step = nil) click to toggle source
# File lib/foreman_maintain/runner.rb, line 43
def ask_to_quit(_step = nil)
  @quit = true
end
assumeyes?() click to toggle source
# File lib/foreman_maintain/runner.rb, line 14
def assumeyes?
  @assumeyes
end
run() click to toggle source
# File lib/foreman_maintain/runner.rb, line 24
def run
  scenarios_with_dependencies.each do |scenario|
    run_scenario(scenario)
  end
end
run_scenario(scenario) click to toggle source
# File lib/foreman_maintain/runner.rb, line 30
def run_scenario(scenario)
  @steps_to_run = scenario.steps.dup
  @reporter.before_scenario_starts(scenario)
  while !@quit && !@steps_to_run.empty?
    step = @steps_to_run.shift
    @reporter.puts('Rerunning the check after fix procedure') if rerun_check?(step)
    execution = Execution.new(step, @reporter)
    execution.run
    ask_about_offered_steps(step)
  end
  @reporter.after_scenario_finishes(scenario)
end
scenarios_with_dependencies() click to toggle source
# File lib/foreman_maintain/runner.rb, line 18
def scenarios_with_dependencies
  @scenarios.map do |scenario|
    scenario.before_scenarios + [scenario]
  end.flatten
end

Private Instance Methods

ask_about_offered_steps(step) click to toggle source

rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity

# File lib/foreman_maintain/runner.rb, line 58
def ask_about_offered_steps(step)
  if assumeyes? && rerun_check?(step)
    @reporter.puts 'Check still failing after attempt to fix. Skipping'
    return :no
  end
  if step.next_steps && !step.next_steps.empty?
    @last_decision_step = step
    steps = step.next_steps.map(&:ensure_instance)
    decision = @reporter.on_next_steps(steps)
    case decision
    when :quit
      ask_to_quit
    when Executable
      chosen_steps = [decision]
      chosen_steps << step if step.is_a?(Check)
      add_steps(*chosen_steps)
    end
  end
end
rerun_check?(step) click to toggle source
# File lib/foreman_maintain/runner.rb, line 78
def rerun_check?(step)
  @last_decision_step == step
end