Class: Runbook::Toolbox

Inherits:
Object
  • Object
show all
Defined in:
lib/runbook/toolbox.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToolbox

Returns a new instance of Toolbox.



5
6
7
# File 'lib/runbook/toolbox.rb', line 5

def initialize
  @prompt = TTY::Prompt.new
end

Instance Attribute Details

#promptObject (readonly)

Returns the value of attribute prompt.



3
4
5
# File 'lib/runbook/toolbox.rb', line 3

def prompt
  @prompt
end

Instance Method Details

#ask(msg, default: nil, echo: true) ⇒ Object



9
10
11
# File 'lib/runbook/toolbox.rb', line 9

def ask(msg, default: nil, echo: true)
  prompt.ask(msg, default: default, echo: echo)
end

#error(msg) ⇒ Object



35
36
37
# File 'lib/runbook/toolbox.rb', line 35

def error(msg)
  prompt.error(msg)
end

#exit(return_value) ⇒ Object



39
40
41
# File 'lib/runbook/toolbox.rb', line 39

def exit(return_value)
  super(return_value)
end

#expand(msg, choices) ⇒ Object



13
14
15
# File 'lib/runbook/toolbox.rb', line 13

def expand(msg, choices)
  prompt.expand(msg, choices)
end

#output(msg) ⇒ Object



27
28
29
# File 'lib/runbook/toolbox.rb', line 27

def output(msg)
  prompt.say(msg)
end

#warn(msg) ⇒ Object



31
32
33
# File 'lib/runbook/toolbox.rb', line 31

def warn(msg)
  prompt.warn(msg)
end

#yes?(msg) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
# File 'lib/runbook/toolbox.rb', line 17

def yes?(msg)
  begin
    prompt.yes?(msg)
  rescue TTY::Prompt::ConversionError
    err_msg = "Unknown input: Please type 'y' or 'n'."
    warn(err_msg)
    retry
  end
end