class ForemanMaintain::Reporter
Constants
- DECISION_MAPPER
Public Instance Methods
after_execution_finishes(_execution)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 21 def after_execution_finishes(_execution); end
after_scenario_finishes(_scenario)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 23 def after_scenario_finishes(_scenario); end
ask(_message)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 43 def ask(_message); end
ask_decision(message, actions_msg: 'y(yes), n(no), q(quit)', assumeyes: assumeyes?, run_strategy: :fail_fast)
click to toggle source
simple yes/no question, returns :yes, :no or :quit rubocop:disable Metrics/LineLength
# File lib/foreman_maintain/reporter.rb, line 55 def ask_decision(message, actions_msg: 'y(yes), n(no), q(quit)', assumeyes: assumeyes?, run_strategy: :fail_fast) actions_msg = 'y(yes), n(no)' if run_strategy == :fail_slow if assumeyes print("#{message} (assuming yes)") return :yes end until_valid_decision do filter_decision(ask("#{message}, [#{actions_msg}]")) end end
assumeyes=(assume)
click to toggle source
rubocop:enable Metrics/LineLength
# File lib/foreman_maintain/reporter.rb, line 68 def assumeyes=(assume) @assumeyes = !!assume end
assumeyes?()
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 45 def assumeyes? @assumeyes end
before_execution_starts(_execution)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 19 def before_execution_starts(_execution); end
before_scenario_starts(_scenario, _last_scenario = nil)
click to toggle source
Each public method is a hook called by executor at the specific point
# File lib/foreman_maintain/reporter.rb, line 17 def before_scenario_starts(_scenario, _last_scenario = nil); end
on_next_steps(steps, run_strategy = :fail_fast)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 25 def on_next_steps(steps, run_strategy = :fail_fast) return if steps.empty? if steps.size > 1 multiple_steps_decision(steps, run_strategy) else single_step_decision(steps.first, run_strategy) end end
plaintext=(plaintext)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 72 def plaintext=(plaintext) @plaintext = !!plaintext end
plaintext?()
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 49 def plaintext? @plaintext end
print(_message)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 39 def print(_message); end
puts(_message)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 41 def puts(_message); end
with_spinner(_message) { |dummy_spinner| ... }
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 35 def with_spinner(_message, &_block) yield DummySpinner.new end
Private Instance Methods
ask_to_select(message, steps, run_strategy)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/foreman_maintain/reporter.rb, line 104 def ask_to_select(message, steps, run_strategy) if assumeyes? puts('(assuming first option)') return steps.first end until_valid_decision do actions = run_strategy == :fail_slow ? 'n(next)' : 'n(next), q(quit)' answer = ask("#{message}, [#{actions}]") if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size steps[answer.to_i - 1] else decision = filter_decision(answer) if decision == :yes steps.first else decision end end end end
filter_decision(answer)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 95 def filter_decision(answer) decision = nil DECISION_MAPPER.each do |options, decision_label| decision = decision_label if options.include?(answer) end decision end
multiple_steps_decision(steps, run_strategy)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 87 def multiple_steps_decision(steps, run_strategy) puts 'There are multiple steps to proceed:' steps.each_with_index do |step, index| puts "#{index + 1}) #{step.description}" end ask_to_select('Select step to continue', steps, run_strategy) end
single_step_decision(step, run_strategy)
click to toggle source
# File lib/foreman_maintain/reporter.rb, line 78 def single_step_decision(step, run_strategy) answer = ask_decision("Continue with step [#{step.description}]?", run_strategy: run_strategy) if answer == :yes step else answer end end
until_valid_decision() { |until decision| ... }
click to toggle source
loop over the block until it returns some non-false value
# File lib/foreman_maintain/reporter.rb, line 128 def until_valid_decision decision = nil decision = yield until decision decision end