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.



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

def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @spinner = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].cycle
end

Instance Method Details

#attention(message) ⇒ Object



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

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

#clear_lineObject



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

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

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#error(message) ⇒ Object



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

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

#ok(message) ⇒ Object



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

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

#while_spinning(message) ⇒ Object



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

def while_spinning(message, &)
  thread = Thread.new(&)
  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