Class: Mongify::Mongoid::UI
- Inherits:
-
Object
- Object
- Mongify::Mongoid::UI
- Defined in:
- lib/mongify/mongoid/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
40 41 42 43 |
# File 'lib/mongify/mongoid/ui.rb', line 40 def abort() UI.puts "PROGRAM HALT: #{}" Kernel.abort end |
.ask(msg) ⇒ Object
Asks a yes or no question and waits for reply
30 31 32 |
# File 'lib/mongify/mongoid/ui.rb', line 30 def ask(msg) request("#{msg} [yn] ") == 'y' end |
.gets ⇒ Object
Gets input from user
19 20 21 |
# File 'lib/mongify/mongoid/ui.rb', line 19 def gets in_stream ? in_stream.gets : '' end |
.in_stream ⇒ Object
Incoming stream
46 47 48 |
# File 'lib/mongify/mongoid/ui.rb', line 46 def in_stream $stdin end |
.out_stream ⇒ Object
Output stream
50 51 52 |
# File 'lib/mongify/mongoid/ui.rb', line 50 def out_stream $stdout end |
.print(msg) ⇒ Object
Outputs to stream using print method
14 15 16 |
# File 'lib/mongify/mongoid/ui.rb', line 14 def print(msg) out_stream.print(msg) if out_stream end |
.puts(msg) ⇒ Object
Outputs to stream using puts method
9 10 11 |
# File 'lib/mongify/mongoid/ui.rb', line 9 def puts(msg) out_stream.puts(msg) if out_stream end |
.request(msg) ⇒ Object
Outputs a question and gets input
24 25 26 27 |
# File 'lib/mongify/mongoid/ui.rb', line 24 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
58 59 60 |
# File 'lib/mongify/mongoid/ui.rb', line 58 def terminal_helper @terminal_helper ||= HighLine.new end |
.warn(msg) ⇒ Object
Outputs a Warning (using puts command)
35 36 37 |
# File 'lib/mongify/mongoid/ui.rb', line 35 def warn(msg) puts "WARNING: #{msg}" end |