Class: Mongify::UI
- Inherits:
-
Object
- Object
- Mongify::UI
- Defined in:
- lib/mongify/ui.rb
Overview
Used to output messages to the UI
Class Method Summary collapse
-
.abort(message) ⇒ Object
Outputs a message and aborts execution of app.
-
.ask(msg) ⇒ Object
Asks a yes or no question and waits for reply.
-
.gets ⇒ Object
Gets input from user.
-
.in_stream ⇒ Object
Incoming stream.
-
.out_stream ⇒ Object
Output stream.
-
.print(msg) ⇒ Object
Outputs to stream using print method.
-
.puts(msg) ⇒ Object
Outputs to stream using puts method.
-
.request(msg) ⇒ Object
Outputs a question and gets input.
-
.terminal_helper ⇒ HighLine
Creates an instance of HighLine which lets us figure out width of console plus a whole lot more.
-
.warn(msg) ⇒ Object
Outputs a Warning (using puts command).
Class Method Details
.abort(message) ⇒ Object
Outputs a message and aborts execution of app
39 40 41 42 |
# File 'lib/mongify/ui.rb', line 39 def abort() UI.puts "PROGRAM HALT: #{}" Kernel.abort end |
.ask(msg) ⇒ Object
Asks a yes or no question and waits for reply
29 30 31 |
# File 'lib/mongify/ui.rb', line 29 def ask(msg) request("#{msg} [yn] ") == 'y' end |
.gets ⇒ Object
Gets input from user
18 19 20 |
# File 'lib/mongify/ui.rb', line 18 def gets in_stream ? in_stream.gets : '' end |
.in_stream ⇒ Object
Incoming stream
45 46 47 |
# File 'lib/mongify/ui.rb', line 45 def in_stream Configuration.in_stream end |
.out_stream ⇒ Object
Output stream
49 50 51 |
# File 'lib/mongify/ui.rb', line 49 def out_stream Configuration.out_stream end |
.print(msg) ⇒ Object
Outputs to stream using print method
13 14 15 |
# File 'lib/mongify/ui.rb', line 13 def print(msg) out_stream.print(msg) if out_stream end |
.puts(msg) ⇒ Object
Outputs to stream using puts method
8 9 10 |
# File 'lib/mongify/ui.rb', line 8 def puts(msg) out_stream.puts(msg) if out_stream end |
.request(msg) ⇒ Object
Outputs a question and gets input
23 24 25 26 |
# File 'lib/mongify/ui.rb', line 23 def request(msg) print(msg) gets.chomp end |
.terminal_helper ⇒ HighLine
Creates an instance of HighLine which lets us figure out width of console plus a whole lot more
57 58 59 |
# File 'lib/mongify/ui.rb', line 57 def terminal_helper @terminal_helper ||= HighLine.new end |
.warn(msg) ⇒ Object
Outputs a Warning (using puts command)
34 35 36 |
# File 'lib/mongify/ui.rb', line 34 def warn(msg) puts "WARNING: #{msg}" end |