Class: AndSon::TestClient

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/and-son/client.rb

Defined Under Namespace

Classes: Call

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Client

included, new

Constructor Details

#initialize(host, port) ⇒ TestClient

Returns a new instance of TestClient.



62
63
64
65
66
67
# File 'lib/and-son/client.rb', line 62

def initialize(host, port)
  super
  @params_value = {}
  @calls = []
  @responses = AndSon::StoredResponses.new
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



60
61
62
# File 'lib/and-son/client.rb', line 60

def calls
  @calls
end

#logger_valueObject

Returns the value of attribute logger_value.



59
60
61
# File 'lib/and-son/client.rb', line 59

def logger_value
  @logger_value
end

#params_valueObject

Returns the value of attribute params_value.



59
60
61
# File 'lib/and-son/client.rb', line 59

def params_value
  @params_value
end

#responsesObject (readonly)

Returns the value of attribute responses.



60
61
62
# File 'lib/and-son/client.rb', line 60

def responses
  @responses
end

#timeout_valueObject

Returns the value of attribute timeout_value.



59
60
61
# File 'lib/and-son/client.rb', line 59

def timeout_value
  @timeout_value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



104
105
106
# File 'lib/and-son/client.rb', line 104

def ==(other)
  other.kind_of?(self.class) ? self.hash == other.hash : super
end

#add_response(*args, &block) ⇒ Object



82
83
84
# File 'lib/and-son/client.rb', line 82

def add_response(*args, &block)
  self.responses.add(*args, &block)
end

#call(name, params = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/and-son/client.rb', line 69

def call(name, params = nil)
  params ||= {}
  response = self.responses.get(name, params)
  self.calls << Call.new(name, params, response.protocol_response)
  if block_given?
    yield response.protocol_response
  else
    response.data
  end
end

#call_runnerObject



80
# File 'lib/and-son/client.rb', line 80

def call_runner; self; end

#hashObject



95
96
97
98
99
100
101
102
# File 'lib/and-son/client.rb', line 95

def hash
  [ self.host,
    self.port,
    self.timeout_value,
    self.params_value,
    self.logger_value
  ].hash
end

#remove_response(*args) ⇒ Object



86
87
88
# File 'lib/and-son/client.rb', line 86

def remove_response(*args)
  self.responses.remove(*args)
end

#resetObject



90
91
92
93
# File 'lib/and-son/client.rb', line 90

def reset
  self.calls.clear
  self.responses.remove_all
end