module CitrusAdmin::Protocol
Constants
- PRO_FAIL
- PRO_OK
Public Instance Methods
clone_error(origin)
click to toggle source
Clone error
@private
# File lib/citrus-admin/util/protocol.rb, line 76 def clone_error origin if origin.is_a? Exception return { :msg => origin.message, :stack => nil } end return origin end
compose_command(req_id, command, module_id, body)
click to toggle source
Compose command
@param [Integer] req_id @param [String] command @param [String] module_id @param [Object] body
# File lib/citrus-admin/util/protocol.rb, line 47 def compose_command req_id, command, module_id, body if req_id # command message { :req_id => req_id, :command => command, :module_id => module_id, :body => body } else { :command => command, :module_id => module_id, :body => body } end end
compose_request(req_id, module_id, body)
click to toggle source
Componse request
@param [Integer] req_id @param [String] module_id @param [Object] body
# File lib/citrus-admin/util/protocol.rb, line 21 def compose_request req_id, module_id, body if req_id # request message { :req_id => req_id, :module_id => module_id, :body => body } else # notify message { :module_id => module_id, :body => body } end end
compose_response(msg, err, res)
click to toggle source
Compose response
@param [Object] msg @param [Object] err @param [Object] res
# File lib/citrus-admin/util/protocol.rb, line 36 def compose_response msg, err, res return nil unless msg[:req_id] { :resp_id => msg[:req_id], :err => clone_error(err), :body => res } end
is_request?(msg)
click to toggle source
Determine if a message is a request
@param [Object] msg
# File lib/citrus-admin/util/protocol.rb, line 69 def is_request? msg msg && msg[:req_id] end
parse(msg)
click to toggle source
Parse message
@param [String] msg
# File lib/citrus-admin/util/protocol.rb, line 59 def parse msg begin JSON.parse msg, { :symbolize_names => true } rescue => err end end