Class: AbCrunch::LogConsoleWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/abcrunch/log_console_writer.rb

Constant Summary collapse

TYPE_STYLES =
{
  :info => { :color => :white, :prefix => '  ' },
  :test => { :color => :light_white, :prefix => "\n\n-----" },
  :strategy => { :color => :light_white, :prefix => "\n" },
  :task => { :color => :white, :prefix => "\n " },
  :progress => { :color => :green, :prefix => '  ' },
  :result => { :color => :light_green, :prefix => '  ' },
  :ab_result => { :color => :cyan, :prefix => '    ' },
  :success => { :color => :light_green, :prefix => '  ' },
  :failure => { :color => :light_red, :prefix => '  ' },
  :summary => { :color => :light_white, :prefix => '' },
  :summary_title => { :color => :light_white, :prefix => "\n==================== " },
  :summary_passed => { :color => :light_green, :prefix => '' },
  :summary_failed => { :color => :light_red, :prefix => '' },

}
@@last_inline =
false

Class Method Summary collapse

Class Method Details

.color_for_type(type) ⇒ Object



24
25
26
# File 'lib/abcrunch/log_console_writer.rb', line 24

def self.color_for_type(type)
  TYPE_STYLES[type] ? TYPE_STYLES[type][:color] : :white
end

.log(type, message, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/abcrunch/log_console_writer.rb', line 32

def self.log(type, message, options = {})
  a_message = prefix_for_type(type) + message
  if options[:inline]
    print a_message.send(color_for_type type)
    @@last_inline = true
  else
    a_message = "\n#{a_message}" if @@last_inline
    puts a_message.send(color_for_type type)
    @@last_inline = false
  end
end

.prefix_for_type(type) ⇒ Object



28
29
30
# File 'lib/abcrunch/log_console_writer.rb', line 28

def self.prefix_for_type(type)
  TYPE_STYLES[type] ? TYPE_STYLES[type][:prefix] : ''
end