Class: BoPeep::Localhost::CommandOutcome

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callbacks: nil, log:) ⇒ CommandOutcome

Returns a new instance of CommandOutcome.



613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/bopeep.rb', line 613

def initialize(callbacks: nil, log:)
  @callbacks = Host::Callbacks.from(callbacks)

  if log
    @console_status = Console::HostStatus.new(LOCALHOST)
  else
    @console_status = Console::HostStatus::DEV_NULL
  end

  @started_at = nil
  @finished_at = nil
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



611
612
613
# File 'lib/bopeep.rb', line 611

def error
  @error
end

Instance Method Details

#command_finished!Object



641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/bopeep.rb', line 641

def command_finished!
  @finished_at = Time.now
  @finished_at.freeze

  if successful?
    @console_status.success!
    @callbacks.on_success(self)
  else
    @console_status.failed!(failure_summary)
    @callbacks.on_failure(self)
  end
end

#command_started!Object



634
635
636
637
638
639
# File 'lib/bopeep.rb', line 634

def command_started!
  @started_at = Time.now
  @started_at.freeze

  @console_status.started!
end

#durationObject



670
671
672
673
674
# File 'lib/bopeep.rb', line 670

def duration
  if @started_at && @finished_at
    @finished_at - @started_at
  end
end

#failed?Boolean

Returns:

  • (Boolean)


658
659
660
# File 'lib/bopeep.rb', line 658

def failed?
  !successful?
end

#failure_reasonObject



676
677
678
# File 'lib/bopeep.rb', line 676

def failure_reason
  error
end

#failure_summaryObject



680
681
682
# File 'lib/bopeep.rb', line 680

def failure_summary
  error && error.full_message
end

#finished?Boolean

Returns:

  • (Boolean)


666
667
668
# File 'lib/bopeep.rb', line 666

def finished?
  not @finished_at.nil?
end

#hostObject



626
627
628
# File 'lib/bopeep.rb', line 626

def host
  LOCALHOST
end

#started?Boolean

Returns:

  • (Boolean)


662
663
664
# File 'lib/bopeep.rb', line 662

def started?
  not @started_at.nil?
end

#successful?Boolean

Returns:

  • (Boolean)


654
655
656
# File 'lib/bopeep.rb', line 654

def successful?
  error.nil?
end

#valueObject



630
631
632
# File 'lib/bopeep.rb', line 630

def value
  self
end