Kouhei Sutou
null+****@clear*****
Thu Nov 21 13:04:10 JST 2013
Kouhei Sutou 2013-11-21 13:04:10 +0900 (Thu, 21 Nov 2013) New Revision: 7a8c70c90f4c007220fb427941f1c68171426340 https://github.com/droonga/droonga-client-ruby/commit/7a8c70c90f4c007220fb427941f1c68171426340 Message: Merge #send_receive to #send Modified files: lib/droonga/client/connection/droonga_protocol.rb Modified: lib/droonga/client/connection/droonga_protocol.rb (+25 -13) =================================================================== --- lib/droonga/client/connection/droonga_protocol.rb 2013-11-21 13:03:49 +0900 (fcb7b39) +++ lib/droonga/client/connection/droonga_protocol.rb 2013-11-21 13:04:10 +0900 (bef4f9b) @@ -40,22 +40,34 @@ module Droonga "type" => "search", "body" => body, } - send_receive(envelope) + send(envelope, :response => :one) end - def send(envelope) - @logger.post("message", envelope) - end - - def send_receive(envelope) - receiver = Receiver.new - begin - envelope = envelope.dup - envelope["replyTo"] = "#{receiver.host}:#{receiver.port}/droonga" + # Sends low level request. Normally, you should use other + # convenience methods. + # + # @param envelope [Hash] Request envelope. + # @param options [Hash] The options to send request. + # @option options :response [nil, :none, :one] (nil) The response type. + # If you specify `nil`, it is treated as `:one`. + # @return The response. TODO: WRITE ME + def send(envelope, options={}) + response_type = options[:response] || :one + case response_type + when :none @logger.post("message", envelope) - receiver.receive(:timeout => @timeout) - ensure - receiver.close + when :one + receiver = Receiver.new + begin + envelope = envelope.dup + envelope["replyTo"] = "#{receiver.host}:#{receiver.port}/droonga" + @logger.post("message", envelope) + receiver.receive(:timeout => @timeout) + ensure + receiver.close + end + else + raise InvalidResponseType.new(response_type) end end -------------- next part -------------- HTML����������������������������... Download