Module: Fargo::Protocol::DC
Instance Attribute Summary collapse
Instance Method Summary
collapse
#parse_command_message, #parse_message
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6
7
8
|
# File 'lib/fargo/protocol/dc.rb', line 6
def client
@client
end
|
Instance Method Details
#connection_type ⇒ Object
55
56
57
|
# File 'lib/fargo/protocol/dc.rb', line 55
def connection_type
:dc
end
|
#parse_data? ⇒ Boolean
34
35
36
|
# File 'lib/fargo/protocol/dc.rb', line 34
def parse_data?
true
end
|
#post_init ⇒ Object
8
9
10
|
# File 'lib/fargo/protocol/dc.rb', line 8
def post_init
@received_data = ''
end
|
#publish_args ⇒ Object
51
52
53
|
# File 'lib/fargo/protocol/dc.rb', line 51
def publish_args
{}
end
|
#receive_data(data) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/fargo/protocol/dc.rb', line 38
def receive_data data
if parse_data?
@received_data << data
while parse_data? && chunk = @received_data.slice!(/[^\|]+\|/)
receive_data_chunk chunk
end
else
receive_data_chunk @received_data + data
@received_data = ''
end
end
|
#receive_data_chunk(chunk) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/fargo/protocol/dc.rb', line 27
def receive_data_chunk chunk
chunk.chomp! '|'
Fargo.logger.debug "#{self}: Received: #{chunk.inspect}"
hash = parse_message chunk
receive_message hash[:type], hash
end
|
#receive_message(type, message) ⇒ Object
12
13
14
|
# File 'lib/fargo/protocol/dc.rb', line 12
def receive_message type, message
client.channel << [type, message] if client
end
|
#send_message(method, args = nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fargo/protocol/dc.rb', line 16
def send_message method, args = nil
if args
data = "$#{method} #{args}|"
else
data = "$#{method}|"
end
Fargo.logger.debug "#{self} Sending: #{data.inspect}"
send_data data
end
|
#unbind ⇒ Object
59
60
61
62
63
64
|
# File 'lib/fargo/protocol/dc.rb', line 59
def unbind
if client
args = [:"#{connection_type}_disconnected", publish_args]
client.channel << args
end
end
|