Class: FIS::UI

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fis/ui.rb

Overview

Class responsible for displaying different level information

Instance Method Summary collapse

Constructor Details

#initialize(prompt) ⇒ UI

Returns a new instance of UI.



12
13
14
15
16
# File 'lib/fis/ui.rb', line 12

def initialize(prompt)
  @prompt = prompt
  @debug = ENV['DEBUG']
  @shell = Thor::Shell::Basic.new
end

Instance Method Details

#debug(error, newline = nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/fis/ui.rb', line 34

def debug(error, newline = nil)
  return unless @debug

  message = ["#{error.class}: #{error.message}", *error.backtrace]
  @prompt.say(newline ? message.join("\n") : message)
end

#debug!Object



41
42
43
# File 'lib/fis/ui.rb', line 41

def debug!
  @debug = true
end

#error(message) ⇒ Object



30
31
32
# File 'lib/fis/ui.rb', line 30

def error(message)
  @prompt.error(message)
end


53
54
55
# File 'lib/fis/ui.rb', line 53

def format_link(title, url)
  TTY::Link.link_to(title, url)
end

#info(message) ⇒ Object



22
23
24
# File 'lib/fis/ui.rb', line 22

def info(message)
  @prompt.say(message)
end

#newline(num = 1) ⇒ Object



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

def newline(num = 1)
  @prompt.say("\n" * num)
end


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

def print_link(title, url)
  @prompt.say(format_link(title, url))
end


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

def print_table(table, options = {})
  @shell.print_table(table, options)
end

#warn(message) ⇒ Object



26
27
28
# File 'lib/fis/ui.rb', line 26

def warn(message)
  @prompt.warn(message)
end