Class: ForemanMaintain::Runner
- Inherits:
-
Object
- Object
- ForemanMaintain::Runner
- Defined in:
- lib/foreman_maintain/runner.rb,
lib/foreman_maintain/runner/execution.rb,
lib/foreman_maintain/runner/stored_execution.rb
Overview
Class responsible for running the scenario
Direct Known Subclasses
Defined Under Namespace
Classes: Execution, StoredExecution
Instance Attribute Summary collapse
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
- #add_steps(*steps) ⇒ Object
- #ask_to_quit(exit_code = 1) ⇒ Object
- #assumeyes? ⇒ Boolean
- #confirm_scenario(scenario) ⇒ Object
-
#initialize(reporter, scenarios, options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #quit? ⇒ Boolean
- #run ⇒ Object
-
#run_scenario(scenario, confirm = true) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #storage ⇒ Object
-
#whitelisted_step?(step) ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity.
Constructor Details
#initialize(reporter, scenarios, options = {}) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/foreman_maintain/runner.rb', line 8 def initialize(reporter, scenarios, = {}) .(:assumeyes, :whitelist, :force) @assumeyes = .fetch(:assumeyes, false) @whitelist = .fetch(:whitelist, []) @force = .fetch(:force, false) @reporter = reporter @scenarios = Array(scenarios) @quit = false @last_scenario = nil @exit_code = 0 end |
Instance Attribute Details
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
4 5 6 |
# File 'lib/foreman_maintain/runner.rb', line 4 def exit_code @exit_code end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
4 5 6 |
# File 'lib/foreman_maintain/runner.rb', line 4 def reporter @reporter end |
Instance Method Details
#add_steps(*steps) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/foreman_maintain/runner.rb', line 73 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(exit_code = 1) ⇒ Object
68 69 70 71 |
# File 'lib/foreman_maintain/runner.rb', line 68 def ask_to_quit(exit_code = 1) @quit = true @exit_code = exit_code end |
#assumeyes? ⇒ Boolean
24 25 26 |
# File 'lib/foreman_maintain/runner.rb', line 24 def assumeyes? @assumeyes end |
#confirm_scenario(scenario) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/foreman_maintain/runner.rb', line 56 def confirm_scenario(scenario) return unless @last_scenario decision = if @last_scenario.steps_with_error(:whitelisted => false).any? :quit elsif @last_scenario.steps_with_warning(:whitelisted => false).any? reporter.ask_decision("Continue with [#{scenario.description}]") end ask_to_quit if [:quit, :no].include?(decision) decision end |
#quit? ⇒ Boolean
20 21 22 |
# File 'lib/foreman_maintain/runner.rb', line 20 def quit? @quit end |
#run ⇒ Object
28 29 30 31 32 33 |
# File 'lib/foreman_maintain/runner.rb', line 28 def run @scenarios.each do |scenario| run_scenario(scenario) break if @quit end end |
#run_scenario(scenario, confirm = true) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/foreman_maintain/runner.rb', line 36 def run_scenario(scenario, confirm = true) return if scenario.steps.empty? raise 'The runner is already in quit state' if quit? if confirm confirm_scenario(scenario) return if quit? end execute_scenario_steps(scenario) ensure @last_scenario = scenario unless scenario.steps.empty? @exit_code = 1 if scenario.failed? end |
#storage ⇒ Object
81 82 83 |
# File 'lib/foreman_maintain/runner.rb', line 81 def storage ForemanMaintain.storage(:default) end |
#whitelisted_step?(step) ⇒ Boolean
rubocop:enable Metrics/CyclomaticComplexity
52 53 54 |
# File 'lib/foreman_maintain/runner.rb', line 52 def whitelisted_step?(step) @whitelist.include?(step.label_dashed.to_s) end |