Module: Fargo::Protocol::DC

Includes:
Fargo::Parser
Included in:
Download, Hub
Defined in:
lib/fargo/protocol/dc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fargo::Parser

#parse_command_message, #parse_message

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/fargo/protocol/dc.rb', line 6

def client
  @client
end

Instance Method Details

#post_initObject



8
9
10
# File 'lib/fargo/protocol/dc.rb', line 8

def post_init
  @received_data = ''
end

#publish_argsObject



38
39
40
# File 'lib/fargo/protocol/dc.rb', line 38

def publish_args
  {}
end

#receive_data(data) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/fargo/protocol/dc.rb', line 27

def receive_data data
  @received_data << data

  while message = @received_data.slice!(/[^\|]+\|/)
    message.chomp! '|'
    Fargo.logger.debug "#{self}: Received: #{message.inspect}"
    hash = parse_message message
    receive_message hash[:type], hash
  end
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

#unbindObject



42
43
44
45
46
47
48
# File 'lib/fargo/protocol/dc.rb', line 42

def unbind
  if client
    connection_type = self.class.name.split('::').last.downcase
    args = [:"#{connection_type}_disconnected", publish_args]
    client.channel << args
  end
end