Class: Bundleup::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bundleup/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ Logger

Returns a new instance of Logger.



9
10
11
12
13
14
# File 'lib/bundleup/logger.rb', line 9

def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @spinner = %w[         ].cycle
end

Instance Method Details

#attention(message) ⇒ Object



24
25
26
# File 'lib/bundleup/logger.rb', line 24

def attention(message)
  puts Colors.yellow(message)
end

#clear_lineObject



33
34
35
36
# File 'lib/bundleup/logger.rb', line 33

def clear_line
  print "\r".ljust(console_width - 1)
  print "\r"
end

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/bundleup/logger.rb', line 28

def confirm?(question)
  print Colors.yellow(question.sub(/\??\z/, " [Yn]? "))
  gets =~ /^($|y)/i
end

#error(message) ⇒ Object



20
21
22
# File 'lib/bundleup/logger.rb', line 20

def error(message)
  stderr.puts Colors.red("ERROR: #{message}")
end

#ok(message) ⇒ Object



16
17
18
# File 'lib/bundleup/logger.rb', line 16

def ok(message)
  puts Colors.green("#{message}")
end

#while_spinning(message, &block) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/bundleup/logger.rb', line 38

def while_spinning(message, &block)
  thread = Thread.new(&block)
  thread.report_on_exception = false
  message = message.ljust(console_width - 2)
  print "\r#{Colors.blue([spinner.next, message].join(' '))}" until wait_for_exit(thread, 0.1)
  thread.value
end