Sha256: 0f287d8a2140a00f6f3ee99a92643166c786e16e1aa54004b222974a8f9c151b

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

module RabbitRPC
  class MessageParserException; end

  class MessageParser
    attr_reader :service_name, :method_name

    # methods with the following prefix will not wait
    # for a response
    ONE_WAY_PREFIX = 'one_way'

    def initialize(message)
      @message = message
    end

    # Public: Extracts the Service name and method name
    #
    # Examples
    #
    #  "UserService.create"
    #  # => "UserService", "create"
    #
    # Returns nothing
    def parse
      method = @message.is_a?(RabbitRPC::Message) ? @message.method_name : @message['method']
      @service_name, @method_name = method.split('.')
    end

    # Public: Identifies whether a wait for a response is expected
    #
    # Returns a Boolean
    def one_way?
      parse if @method_name.nil?
      @method_name.start_with?(ONE_WAY_PREFIX)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_rpc-0.0.2 lib/rabbit_rpc/message_parser.rb