Class: FCS::Request
- Inherits:
-
Object
show all
- Defined in:
- lib/fcs/request.rb
Constant Summary
collapse
- VALID_HASH_COMMANDS =
[:sendmsg, :sendevent]
- VALID_STRING_COMMANDS =
[:api, :bgapi, :event, :myevents, :divert_events,
:filter, :exit, :auth, :log, :nolog, :nixevent,
:noevents]
- VALID_COMMANDS =
VALID_HASH_COMMANDS + VALID_STRING_COMMANDS
Instance Method Summary
collapse
Constructor Details
#initialize(socket, response_class = Response) ⇒ Request
Returns a new instance of Request.
11
12
13
14
|
# File 'lib/fcs/request.rb', line 11
def initialize(socket, response_class=Response)
@socket = socket
@response_class = response_class
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/fcs/request.rb', line 35
def method_missing(method, *args, &block)
if @response_class.method_defined?(method)
dispatch!.send(method, *args, &block)
else
update_command(method, *args, &block)
self
end
end
|
Instance Method Details
#dispatch! ⇒ Object
26
27
28
|
# File 'lib/fcs/request.rb', line 26
def dispatch!
dispatch_raw!("#{generate_command}\n\n")
end
|
#dispatch_raw!(command) ⇒ Object
30
31
32
33
|
# File 'lib/fcs/request.rb', line 30
def dispatch_raw!(command)
@socket.write(command)
@response_class.new(@socket).parse_and_respond
end
|
#generate_command ⇒ Object
16
17
18
19
|
# File 'lib/fcs/request.rb', line 16
def generate_command
raise NotImplementedError
end
|
#update_command(method, *args, &block) ⇒ Object
21
22
23
24
|
# File 'lib/fcs/request.rb', line 21
def update_command(method, *args, &block)
raise NotImplementedError
end
|