Class: Plywood::FancyLogger::FancyLog

Inherits:
Object
  • Object
show all
Defined in:
lib/plywood/fancy_logger/fancy_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ FancyLog

Returns a new instance of FancyLog.



8
9
10
11
12
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 8

def initialize(name)
  @name = name
  @exit_status = nil
  @output = Concurrent::Array.new
end

Instance Attribute Details

#exit_statusObject

Returns the value of attribute exit_status.



6
7
8
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 6

def exit_status
  @exit_status
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 6

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



6
7
8
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 6

def output
  @output
end

Instance Method Details

#add_line(stream) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 14

def add_line(stream)
  raise "Process exited" unless exit_status.nil?
  stream.gets.each_line do |line|
    @output << [(stream.err? ? :stderr : :stdout), line]
  end
  self
end

#iconObject



46
47
48
49
50
51
52
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 46

def icon
  case exit_status
  when nil then "⏵"
  when 0 then "✔"
  else "‼"
  end
end

#running?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 26

def running?
  @exit_status.nil?
end

#statusObject



38
39
40
41
42
43
44
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 38

def status
  case exit_status
  when nil then "running"
  when 0 then "success"
  else "failed (#{exit_status})"
  end
end

#success?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 30

def success?
  @exit_status&.zero?
end

#to_sObject



34
35
36
# File 'lib/plywood/fancy_logger/fancy_log.rb', line 34

def to_s
  "#{icon} #{name} | #{status}"
end