Class: Mongify::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/mongify/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



39
40
41
42
# File 'lib/mongify/ui.rb', line 39

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



29
30
31
# File 'lib/mongify/ui.rb', line 29

def ask(msg)
  request("#{msg} [yn] ") == 'y'
end

.getsObject

Gets input from user



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

def gets
  in_stream ? in_stream.gets : ''
end

.in_streamObject

Incoming stream



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

def in_stream
  Configuration.in_stream
end

.out_streamObject

Output stream



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

def out_stream
  Configuration.out_stream
end

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_helperHighLine

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

Returns:

  • (HighLine)

    instance



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