Class: FCS::HashRequest

Inherits:
Request show all
Defined in:
lib/fcs/hash_request.rb

Direct Known Subclasses

SendmsgRequest

Constant Summary

Constants inherited from Request

Request::VALID_COMMANDS, Request::VALID_HASH_COMMANDS, Request::VALID_STRING_COMMANDS

Instance Method Summary collapse

Methods inherited from Request

#dispatch!, #dispatch_raw!, #method_missing

Constructor Details

#initialize(socket) ⇒ HashRequest

Returns a new instance of HashRequest.



5
6
7
8
9
10
# File 'lib/fcs/hash_request.rb', line 5

def initialize(socket)
  super(socket)
  @command_type = ''
  @command_value = ''
  @params = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FCS::Request

Instance Method Details

#generate_commandObject



12
13
14
15
16
17
18
# File 'lib/fcs/hash_request.rb', line 12

def generate_command
  # TODO if app args is longer than 2048 octet limit, use alternate format
  cmd = "#{@command_type} #{@command_value}\n"
  cmd << @params.map do |k,v|
    "#{k.gsub(/_/, '-')}: #{v}"
  end.join("\n") if not @params.empty?
end

#update_command(method, *args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fcs/hash_request.rb', line 20

def update_command(method, *args, &block)
  arg_string = args.map(&:to_s).join(' ') || ''

  # assume the first call here is the command type and value
  if @command_type.empty?
    @command_type = method.to_s
    @command_value = arg_string
  else
    @params[method.to_s] = arg_string
  end
end