Class: Specjour::Connection
- Inherits:
-
Object
- Object
- Specjour::Connection
show all
- Extended by:
- Forwardable
- Includes:
- Protocol
- Defined in:
- lib/specjour/connection.rb
Constant Summary
Constant Summary
Constants included
from Protocol
Protocol::TERMINATOR, Protocol::TERMINATOR_REGEXP
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods included from Protocol
#dump_object, #load_object
Constructor Details
A new instance of Connection
18
19
20
21
|
# File 'lib/specjour/connection.rb', line 18
def initialize(uri)
@uri = uri
@retries = 0
end
|
Instance Attribute Details
- (Object) retries
Returns the value of attribute retries
6
7
8
|
# File 'lib/specjour/connection.rb', line 6
def retries
@retries
end
|
- (Object) socket
33
34
35
|
# File 'lib/specjour/connection.rb', line 33
def socket
@socket ||= connect
end
|
- (Object) uri
Returns the value of attribute uri
6
7
8
|
# File 'lib/specjour/connection.rb', line 6
def uri
@uri
end
|
Class Method Details
+ (Object) wrap(established_connection)
11
12
13
14
15
16
|
# File 'lib/specjour/connection.rb', line 11
def self.wrap(established_connection)
host, port = established_connection.peeraddr.values_at(3,1)
connection = new URI::Generic.build(:host => host, :port => port)
connection.socket = established_connection
connection
end
|
Instance Method Details
- (Object) connect
25
26
27
|
# File 'lib/specjour/connection.rb', line 25
def connect
timeout { connect_socket }
end
|
- (Object) disconnect
29
30
31
|
# File 'lib/specjour/connection.rb', line 29
def disconnect
socket.close if socket && !socket.closed?
end
|
- (Object) next_test
37
38
39
40
41
42
|
# File 'lib/specjour/connection.rb', line 37
def next_test
will_reconnect do
send_message(:ready)
load_object socket.gets(TERMINATOR)
end
end
|
- (Object) print(arg)
44
45
46
47
48
|
# File 'lib/specjour/connection.rb', line 44
def print(arg)
will_reconnect do
socket.print dump_object(arg)
end
end
|
- (Object) puts(arg = '')
50
51
52
53
54
|
# File 'lib/specjour/connection.rb', line 50
def puts(arg='')
will_reconnect do
print(arg << "\n")
end
end
|
- (Object) send_message(method_name, *args)
56
57
58
59
60
61
|
# File 'lib/specjour/connection.rb', line 56
def send_message(method_name, *args)
will_reconnect do
print([method_name, *args])
flush
end
end
|