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.



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

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.



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

def row_number
  @row_number
end

Instance Method Details

#failed!(failure_message = "") ⇒ Object



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

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



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

def last_line_length
  0
end

#newline_countObject



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

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

#started!Object



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

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

  @console.reprint_content(self)
end

#success!Object



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

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

  @console.reprint_content(self)
end

#to_sObject



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

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