Class: PipeRpc::Hub::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/pipe_rpc/hub_message.rb

Defined Under Namespace

Classes: ErrorResponse

Instance Method Summary collapse

Constructor Details

#initialize(hub, body) ⇒ Message

Returns a new instance of Message.



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

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

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pipe_rpc/hub_message.rb', line 18

def error?
  @body.has_key? :error and @body[:id].nil?
end

#handleObject



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

def handle
  if response?
    guarded{ handler.handle if handler }
  else
    handler.handle if handler
  end
end

#request?Boolean

Returns:

  • (Boolean)


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

def request?
  @body.has_key? :method
end

#response?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/pipe_rpc/hub_message.rb', line 14

def response?
  (@body.has_key? :error or @body.has_key? :result) and !!@body[:id]
end