Class: FCS::HashRequest
Direct Known Subclasses
Constant Summary
Constants inherited from Request
Request::VALID_COMMANDS, Request::VALID_HASH_COMMANDS, Request::VALID_STRING_COMMANDS
Instance Method Summary collapse
- #generate_command ⇒ Object
-
#initialize(socket) ⇒ HashRequest
constructor
A new instance of HashRequest.
- #update_command(method, *args, &block) ⇒ Object
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_command ⇒ Object
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 |