Class: Runbook::Toolbox
- Inherits:
-
Object
- Object
- Runbook::Toolbox
- Defined in:
- lib/runbook/toolbox.rb
Instance Attribute Summary collapse
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
- #ask(msg, default: nil, echo: true) ⇒ Object
- #error(msg) ⇒ Object
- #exit(return_value) ⇒ Object
- #expand(msg, choices) ⇒ Object
-
#initialize ⇒ Toolbox
constructor
A new instance of Toolbox.
- #output(msg) ⇒ Object
- #warn(msg) ⇒ Object
- #yes?(msg) ⇒ Boolean
Constructor Details
#initialize ⇒ Toolbox
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
#prompt ⇒ Object (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 (msg, choices) prompt.(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
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 |