Kouhei Sutou
null+****@clear*****
Sat Jul 19 21:57:37 JST 2014
Kouhei Sutou 2014-07-19 21:57:37 +0900 (Sat, 19 Jul 2014) New Revision: 5c3f1926a31695acb19d8b95f3393f6696e6fdeb https://github.com/droonga/droonga-client-ruby/commit/5c3f1926a31695acb19d8b95f3393f6696e6fdeb Message: Set general default values to message in client instead of connections Modified files: lib/droonga/client.rb lib/droonga/client/connection/droonga-protocol/coolio.rb lib/droonga/client/connection/droonga-protocol/thread.rb Modified: lib/droonga/client.rb (+15 -0) =================================================================== --- lib/droonga/client.rb 2014-07-15 09:56:44 +0900 (a854a16) +++ lib/droonga/client.rb 2014-07-19 21:57:37 +0900 (83ff1ae) @@ -64,14 +64,25 @@ module Droonga end def send(message, options={}, &block) + if message["id"].nil? or message["date"].nil? + id = message["id"] || generate_id + date = message["date"] || Time.now + message = message.merge("id" => id, "date" => date) + end @connection.send(message, options, &block) end def request(message, options={}, &block) + if message["id"].nil? + message = message.merge("id" => generate_id) + end @connection.request(message, options, &block) end def subscribe(message, options={}, &block) + if message["id"].nil? + message = message.merge("id" => generate_id) + end @connection.subscribe(message, options, &block) end @@ -92,5 +103,9 @@ module Droonga Connection::DroongaProtocol.new(options) end end + + def generate_id + Time.now.to_f.to_s + end end end Modified: lib/droonga/client/connection/droonga-protocol/coolio.rb (+2 -16) =================================================================== --- lib/droonga/client/connection/droonga-protocol/coolio.rb 2014-07-15 09:56:44 +0900 (d88cc4c) +++ lib/droonga/client/connection/droonga-protocol/coolio.rb 2014-07-19 21:57:37 +0900 (ce777cd) @@ -183,9 +183,7 @@ module Droonga end def request(message, options={}, &block) - id = message["id"] || generate_id - message = message.merge("id" => id, - "replyTo" => @receiver.droonga_name) + message = message.merge("replyTo" => @receiver.droonga_name) send(message, options) do |error| yield(error) end @@ -211,9 +209,7 @@ module Droonga end def subscribe(message, options={}, &block) - id = message["id"] || generate_id - message = message.merge("id" => id, - "replyTo" => @receiver.droonga_name, + message = message.merge("replyTo" => @receiver.droonga_name, "from" => @receiver.droonga_name) send(message, options) do |error| yield(error) @@ -245,11 +241,6 @@ module Droonga end def send(message, options={}, &block) - if message["id"].nil? or message["date"].nil? - id = message["id"] || generate_id - date = message["date"] || Time.now - message = message.merge("id" => id, "date" => date) - end @sender.send("#{@tag}.message", message) do host =****@sende*****[3] port =****@sende*****[1] @@ -263,11 +254,6 @@ module Droonga @sender.close @receiver.close end - - private - def generate_id - Time.now.to_f.to_s - end end end end Modified: lib/droonga/client/connection/droonga-protocol/thread.rb (+0 -4) =================================================================== --- lib/droonga/client/connection/droonga-protocol/thread.rb 2014-07-15 09:56:44 +0900 (3fe6118) +++ lib/droonga/client/connection/droonga-protocol/thread.rb 2014-07-19 21:57:37 +0900 (a217837) @@ -105,10 +105,6 @@ module Droonga end def send(message, options={}, &block) - if message["id"].nil? or message["date"].nil? - message = message.merge("id" => Time.now.to_f.to_s, - "date" => Time.now) - end @logger.post("message", message) end -------------- next part -------------- HTML����������������������������...Download