Class: Warg::Console::HostStatus

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, console) ⇒ HostStatus

Returns a new instance of HostStatus.



426
427
428
429
430
431
432
433
434
435
# File 'lib/warg.rb', line 426

def initialize(host, console)
  @host = host
  @console = console

  @hostname = host.address
  @state = Console::SGR("STARTING").with(text_color: :cyan)
  @failure_message = ""

  @console.puts self
end

Instance Attribute Details

#row_numberObject

Returns the value of attribute row_number.



424
425
426
# File 'lib/warg.rb', line 424

def row_number
  @row_number
end

Instance Method Details

#failed!(failure_message = "") ⇒ Object



451
452
453
454
455
456
# File 'lib/warg.rb', line 451

def failed!(failure_message = "")
  @state = Console::SGR("FAILED").with(text_color: :red, effect: :bold)
  @failure_message = failure_message.to_s

  @console.reprint_content(self)
end

#last_line_lengthObject



441
442
443
# File 'lib/warg.rb', line 441

def last_line_length
  0
end

#newline_countObject



437
438
439
# File 'lib/warg.rb', line 437

def newline_count
  1 + @failure_message.count("\n")
end

#started!Object



445
446
447
448
449
# File 'lib/warg.rb', line 445

def started!
  @state = Console::SGR("RUNNING").with(text_color: :magenta)

  @console.reprint_content(self)
end

#success!Object



458
459
460
461
462
# File 'lib/warg.rb', line 458

def success!
  @state = Console::SGR("DONE").with(text_color: :green)

  @console.reprint_content(self)
end

#to_sObject



464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/warg.rb', line 464

def to_s
  content = "  %-#{Console.hostname_width}s\t[ %s ]\n" % [@hostname, @state]

  unless @failure_message.empty?
    indented_failure_message = @failure_message.each_line.
      map { |line| line.prepend("    ") }.
      join

    content << Console::SGR(indented_failure_message).with(text_color: :yellow)
  end

  content
end