Class: ForemanMaintain::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_maintain/reporter.rb,
lib/foreman_maintain/reporter/cli_reporter.rb

Direct Known Subclasses

CLIReporter

Defined Under Namespace

Classes: CLIReporter, DummySpinner

Constant Summary collapse

DECISION_MAPPER =
{
  %w[y yes] => :yes,
  %w[n next no] => :no,
  %w[q quit] => :quit,
}.freeze

Instance Method Summary collapse

Instance Method Details

#after_execution_finishes(_execution) ⇒ Object



23
24
# File 'lib/foreman_maintain/reporter.rb', line 23

def after_execution_finishes(_execution)
end

#after_scenario_finishes(_scenario) ⇒ Object



26
27
# File 'lib/foreman_maintain/reporter.rb', line 26

def after_scenario_finishes(_scenario)
end

#ask(_message) ⇒ Object



49
50
# File 'lib/foreman_maintain/reporter.rb', line 49

def ask(_message)
end

#ask_decision(message, actions_msg: 'y(yes), n(no), q(quit)', assumeyes: assumeyes?, , run_strategy: :fail_fast) ⇒ Object

simple yes/no question, returns :yes, :no or :quit rubocop:disable Metrics/LineLength



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/foreman_maintain/reporter.rb', line 62

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) ⇒ Object

rubocop:enable Metrics/LineLength



75
76
77
# File 'lib/foreman_maintain/reporter.rb', line 75

def assumeyes=(assume)
  @assumeyes = !!assume
end

#assumeyes?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/foreman_maintain/reporter.rb', line 52

def assumeyes?
  @assumeyes
end

#before_execution_starts(_execution) ⇒ Object



20
21
# File 'lib/foreman_maintain/reporter.rb', line 20

def before_execution_starts(_execution)
end

#before_scenario_starts(_scenario, _last_scenario = nil) ⇒ Object

Each public method is a hook called by executor at the specific point



17
18
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/foreman_maintain/reporter.rb', line 29

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) ⇒ Object



79
80
81
# File 'lib/foreman_maintain/reporter.rb', line 79

def plaintext=(plaintext)
  @plaintext = !!plaintext
end

#plaintext?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/foreman_maintain/reporter.rb', line 56

def plaintext?
  @plaintext
end


43
44
# File 'lib/foreman_maintain/reporter.rb', line 43

def print(_message)
end

#puts(_message) ⇒ Object



46
47
# File 'lib/foreman_maintain/reporter.rb', line 46

def puts(_message)
end

#with_spinner(_message) {|DummySpinner.new| ... } ⇒ Object

Yields:



39
40
41
# File 'lib/foreman_maintain/reporter.rb', line 39

def with_spinner(_message, &_block)
  yield DummySpinner.new
end