Class: Mongify::Mongoid::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/mongify/mongoid/ui.rb

Overview

Used to output messages to the UI

Class Method Summary collapse

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(message)
  UI.puts "PROGRAM HALT: #{message}"
  Kernel.abort message
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

.getsObject

Gets input from user



19
20
21
# File 'lib/mongify/mongoid/ui.rb', line 19

def gets
  in_stream ? in_stream.gets : ''
end

.in_streamObject

Incoming stream



46
47
48
# File 'lib/mongify/mongoid/ui.rb', line 46

def in_stream
  $stdin
end

.out_streamObject

Output stream



50
51
52
# File 'lib/mongify/mongoid/ui.rb', line 50

def out_stream
  $stdout
end

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_helperHighLine

Creates an instance of HighLine which lets us figure out width of console plus a whole lot more

Returns:

  • (HighLine)

    instance



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