Class: PipeRpc::Hub::Request

Inherits:
Request show all
Defined in:
lib/pipe_rpc/hub_request.rb,
lib/pipe_rpc/hub_request_error.rb,
lib/pipe_rpc/hub_request_error_result.rb

Defined Under Namespace

Classes: Error, ErrorResult, Result

Instance Attribute Summary collapse

Attributes inherited from Request

#arguments, #id, #method, #server

Instance Method Summary collapse

Methods inherited from Request

#to_h

Constructor Details

#initialize(hub, body) ⇒ Request

Returns a new instance of Request.



5
6
7
8
# File 'lib/pipe_rpc/hub_request.rb', line 5

def initialize(hub, body)
  @hub = hub
  super body
end

Instance Attribute Details

#hubObject (readonly)

Returns the value of attribute hub.



10
11
12
# File 'lib/pipe_rpc/hub_request.rb', line 10

def hub
  @hub
end

Instance Method Details

#evaluate_result(result = nil, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/pipe_rpc/hub_request.rb', line 21

def evaluate_result(result = nil, &block)
  result = Result.new(self, block_given? ? yield : result)
rescue Exception => e
  result = ErrorResult.new(self, e)
ensure
  asynchronous = result.value == evaluate_result_proc
  @hub.socket.write(result.to_response) unless asynchronous
  return result.value
end

#evaluate_result_procObject



31
32
33
34
35
# File 'lib/pipe_rpc/hub_request.rb', line 31

def evaluate_result_proc
  @evaluate_result_proc ||= proc do |result = nil, &block|
    evaluate_result(result, &block)
  end
end

#handleObject



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

def handle
  evaluate_result do
    # the block is passed for asynchronous evaluation
    mapped_arguments = @hub.transport_mapper.from_transport arguments
    @hub.servers[server].__send__(method, *mapped_arguments, &evaluate_result_proc)
  end
end