Class: Ridley::SSH::ResponseSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/ridley/ssh/response_set.rb

Overview

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(responses = Array.new) ⇒ ResponseSet

Returns a new instance of ResponseSet


30
31
32
33
34
35
# File 'lib/ridley/ssh/response_set.rb', line 30

def initialize(responses = Array.new)
  @failures  = Array.new
  @successes = Array.new

  add_response Array(responses)
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures


25
26
27
# File 'lib/ridley/ssh/response_set.rb', line 25

def failures
  @failures
end

#successesObject (readonly)

Returns the value of attribute successes


26
27
28
# File 'lib/ridley/ssh/response_set.rb', line 26

def successes
  @successes
end

Class Method Details

.merge!(target, other) ⇒ SSH::ResponseSet

Merges the responses of the other ResponseSet with the target ResponseSet and returns the mutated target

Parameters:

Returns:


13
14
15
16
17
18
19
# File 'lib/ridley/ssh/response_set.rb', line 13

def merge!(target, other)
  if other.is_a?(self)
    target.add_response(other.responses)
  end

  target
end

Instance Method Details

#add_response(response) ⇒ Array<SSH::Response> Also known as: <<

Parameters:

Returns:


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ridley/ssh/response_set.rb', line 40

def add_response(response)
  if response.is_a?(Array)
    until response.empty?
      add_response(response.pop)
    end
    return responses
  end

  response.error? ? add_failure(response) : add_success(response)
  responses
end

#has_errors?Boolean

Return true if the response set contains any errors

Returns:

  • (Boolean)

60
61
62
# File 'lib/ridley/ssh/response_set.rb', line 60

def has_errors?
  self.failures.any?
end

#merge(other) ⇒ Ridley::SSH::ResponseSet

Merges the responses of another ResponseSet with self and returns a new instance of ResponseSet

Parameters:

Returns:


70
71
72
73
# File 'lib/ridley/ssh/response_set.rb', line 70

def merge(other)
  target = self.class.new(self.responses) # Why the fuck can't I use #dup here?
  self.class.merge!(target, other)
end

#merge!(other) ⇒ self

Merges the respones of another ResponseSet with self and returns mutated self

Parameters:

Returns:

  • (self)

81
82
83
# File 'lib/ridley/ssh/response_set.rb', line 81

def merge!(other)
  self.class.merge!(self, other)
end

#responsesObject


53
54
55
# File 'lib/ridley/ssh/response_set.rb', line 53

def responses
  successes + failures
end