Class: Bump::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/bump/logger.rb

Overview

The logging class

Instance Method Summary collapse

Constructor Details

#initialize(no_color = nil) ⇒ Logger

Returns a new instance of Logger.



4
5
6
# File 'lib/bump/logger.rb', line 4

def initialize(no_color = nil)
  @no_color = no_color
end

Instance Method Details

#colorize(text, color_code) ⇒ String

Colorize the text by the color code.

Parameters:

  • text (String)
  • color_code (Integer)

Returns:

  • (String)


24
25
26
27
28
29
30
# File 'lib/bump/logger.rb', line 24

def colorize(text, color_code)
  if @no_color
    text
  else
    "\e[#{color_code}m#{text}\e[0m"
  end
end

#green(text) ⇒ String

Returns a green string.

Parameters:

  • text (String)

Returns:

  • (String)


36
37
38
# File 'lib/bump/logger.rb', line 36

def green(text)
  colorize text, 32
end

#log(message = '', breakline = true) ⇒ void

This method returns an undefined value.

Logs the message.

Parameters:

  • message (String) (defaults to: '')
  • breakline (Boolean) (defaults to: true)


13
14
15
16
17
# File 'lib/bump/logger.rb', line 13

def log(message = '', breakline = true)
  print message

  print "\n" if breakline
end

#red(text) ⇒ String

Returns a red string.

Parameters:

  • text (String)

Returns:

  • (String)


44
45
46
# File 'lib/bump/logger.rb', line 44

def red(text)
  colorize text, 31
end