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, summary: true) ⇒ Logger

Creates a new HamlLint::Logger instance.

Parameters:

  • out (IO)

    the output destination.

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

    whether to print summaries



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

def initialize(out, summary: true)
  @out = out
  @summary_enabled = summary
end

Instance Attribute Details

#color_enabledtrue, false

Whether colored output via ANSI escape sequences is enabled.

Returns:

  • (true, false)


8
9
10
# File 'lib/haml_lint/logger.rb', line 8

def color_enabled
  @color_enabled
end

#summary_enabledtrue, false

Whether to output a summary in the log for certain reporters.

Returns:

  • (true, false)


12
13
14
# File 'lib/haml_lint/logger.rb', line 12

def summary_enabled
  @summary_enabled
end

Class Method Details

.silentHamlLint::Logger

Creates a logger which outputs nothing.

Returns:



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

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

Instance Method Details

#bold(*args) ⇒ Object

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

Parameters:

  • args (Array<String>)


42
43
44
# File 'lib/haml_lint/logger.rb', line 42

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

#bold_error(*args) ⇒ Object

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>)


58
59
60
# File 'lib/haml_lint/logger.rb', line 58

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

#error(*args) ⇒ Object

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>)


50
51
52
# File 'lib/haml_lint/logger.rb', line 50

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

#info(*args) ⇒ Object

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>)


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

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

#log(output, newline = true) ⇒ Object

Print the specified output.

Parameters:

  • output (String)

    the output to send

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

    whether to append a newline



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

def log(output, newline = true) # rubocop:disable Style/OptionalBooleanParameter
  @out.print(output)
  @out.print("\n") if newline
end

#newlineObject

Print a blank line.



87
88
89
# File 'lib/haml_lint/logger.rb', line 87

def newline
  log('')
end

#success(*args) ⇒ Object

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>)


66
67
68
# File 'lib/haml_lint/logger.rb', line 66

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

#tty?true, false

Whether this logger is outputting to a TTY.

Returns:

  • (true, false)


94
95
96
# File 'lib/haml_lint/logger.rb', line 94

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

#warning(*args) ⇒ Object

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>)


74
75
76
# File 'lib/haml_lint/logger.rb', line 74

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