Class: HamlLint::Logger

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

Overview

Encapsulates all communication to an output source.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Logger

Creates a new HamlLint::Logger instance.

Parameters:

  • out (IO)

    the output destination.


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

def initialize(out)
  @out = out
end

Instance Attribute Details

#color_enabledtrue, false

Whether colored output via ANSI escape sequences is enabled.

Returns:

  • (true, false)

6
7
8
# File 'lib/haml_lint/logger.rb', line 6

def color_enabled
  @color_enabled
end

Class Method Details

.silentHamlLint::Logger

Creates a logger which outputs nothing.

Returns:


10
11
12
# File 'lib/haml_lint/logger.rb', line 10

def self.silent
  new(File.open('/dev/null', 'w'))
end

Instance Method Details

#bold(*args) ⇒ nil

Print the specified output in bold face. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

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

def bold(*args)
  color('1', *args)
end

#bold_error(*args) ⇒ nil

Print the specified output in a bold face and color indicative of error. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

54
55
56
# File 'lib/haml_lint/logger.rb', line 54

def bold_error(*args)
  color('1;31', *args)
end

#bold_warning(*args) ⇒ nil

Print specified output in bold face in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

81
82
83
# File 'lib/haml_lint/logger.rb', line 81

def bold_warning(*args)
  color('1;33', *args)
end

#error(*args) ⇒ nil

Print the specified output in a color indicative of error. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

45
46
47
# File 'lib/haml_lint/logger.rb', line 45

def error(*args)
  color(31, *args)
end

#info(*args) ⇒ nil

Print the specified output in a color indicating information. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

90
91
92
# File 'lib/haml_lint/logger.rb', line 90

def info(*args)
  color(36, *args)
end

#log(output, newline = true) ⇒ nil

Print the specified output.

Parameters:

  • output (String)

    the output to send

  • newline (true, false) (defaults to: true)

    whether to append a newline

Returns:

  • (nil)

26
27
28
29
# File 'lib/haml_lint/logger.rb', line 26

def log(output, newline = true)
  @out.print(output)
  @out.print("\n") if newline
end

#success(*args) ⇒ nil

Print the specified output in a color indicative of success. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

63
64
65
# File 'lib/haml_lint/logger.rb', line 63

def success(*args)
  color(32, *args)
end

#tty?true, false

Whether this logger is outputting to a TTY.

Returns:

  • (true, false)

97
98
99
# File 'lib/haml_lint/logger.rb', line 97

def tty?
  @out.respond_to?(:tty?) && @out.tty?
end

#warning(*args) ⇒ nil

Print the specified output in a color indicative of a warning. If output destination is not a TTY, behaves the same as #log.

Parameters:

  • args (Array<String>)

Returns:

  • (nil)

72
73
74
# File 'lib/haml_lint/logger.rb', line 72

def warning(*args)
  color(33, *args)
end