Class: RabbitRPC::MessageParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit_rpc/message_parser.rb

Constant Summary collapse

ONE_WAY_PREFIX =

methods with the following prefix will not wait for a response

'one_way'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ MessageParser

Returns a new instance of MessageParser.



11
12
13
# File 'lib/rabbit_rpc/message_parser.rb', line 11

def initialize(message)
  @message = message
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



5
6
7
# File 'lib/rabbit_rpc/message_parser.rb', line 5

def method_name
  @method_name
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



5
6
7
# File 'lib/rabbit_rpc/message_parser.rb', line 5

def service_name
  @service_name
end

Instance Method Details

#one_way?Boolean

Public: Identifies whether a wait for a response is expected

Returns a Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rabbit_rpc/message_parser.rb', line 31

def one_way?
  parse if @method_name.nil?
  @method_name.start_with?(ONE_WAY_PREFIX)
end

#parseObject

Public: Extracts the Service name and method name

Examples

"UserService.create"
# => "UserService", "create"

Returns nothing



23
24
25
26
# File 'lib/rabbit_rpc/message_parser.rb', line 23

def parse
  method = @message.is_a?(RabbitRPC::Message) ? @message.method_name : @message['method']
  @service_name, @method_name = method.split('.')
end