[Groonga-commit] droonga/droonga-client-ruby at 6d0eb2e [master] Add ability to handle errors

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Apr 15 18:20:42 JST 2015


YUKI Hiroshi	2015-04-15 18:20:42 +0900 (Wed, 15 Apr 2015)

  New Revision: 6d0eb2e0da97d112f87ae6609372e6c8ec2e6a9a
  https://github.com/droonga/droonga-client-ruby/commit/6d0eb2e0da97d112f87ae6609372e6c8ec2e6a9a

  Message:
    Add ability to handle errors

  Modified files:
    lib/droonga/client.rb
    lib/droonga/client/connection/droonga-protocol.rb
    lib/droonga/client/connection/http.rb

  Modified: lib/droonga/client.rb (+9 -0)
===================================================================
--- lib/droonga/client.rb    2015-04-15 18:12:17 +0900 (eca5d1d)
+++ lib/droonga/client.rb    2015-04-15 18:20:42 +0900 (fe9be4d)
@@ -31,6 +31,8 @@ module Droonga
     DEFAULT_TAG  = "droonga"
     DEFAULT_DATASET = "Default"
 
+    attr_writer :on_error
+
     class << self
       # Opens a new connection and yields a {Client} object to use the
       # connection. The client is closed after the given block is
@@ -74,6 +76,9 @@ module Droonga
     #   Do or do not validate input messages.
     def initialize(options={})
       @connection = create_connection(options)
+      @connection.on_error = lambda do |error|
+        on_error(error)
+      end
 
       @completion = options[:completion] != false
       @validation = options[:validation] != false
@@ -135,5 +140,9 @@ module Droonga
       end
       @validator.validate(message)
     end
+
+    def on_error(error)
+      @on_error.call(error) if @on_error
+    end
   end
 end

  Modified: lib/droonga/client/connection/droonga-protocol.rb (+9 -0)
===================================================================
--- lib/droonga/client/connection/droonga-protocol.rb    2015-04-15 18:12:17 +0900 (51c4026)
+++ lib/droonga/client/connection/droonga-protocol.rb    2015-04-15 18:20:42 +0900 (0416ee7)
@@ -21,12 +21,17 @@ module Droonga
   class Client
     module Connection
       class DroongaProtocol
+        attr_writer :on_error
+
         def initialize(options={})
           @host = options[:host] || "127.0.0.1"
           @port = options[:port] || 24224
           @tag = options[:tag] || "droonga"
           @options = options
           @backend = create_backend
+          @backend.on_error = lambda do |error|
+            on_error(error)
+          end
         end
 
         # Sends a request message and receives one or more response
@@ -121,6 +126,10 @@ module Droonga
           backend_class = self.class.const_get(backend_name)
           backend_class.new(@host, @port, @tag, @options)
         end
+
+        def on_error(error)
+          @on_error.call(error) if @on_error
+        end
       end
     end
   end

  Modified: lib/droonga/client/connection/http.rb (+6 -0)
===================================================================
--- lib/droonga/client/connection/http.rb    2015-04-15 18:12:17 +0900 (4efb71b)
+++ lib/droonga/client/connection/http.rb    2015-04-15 18:20:42 +0900 (7f73d13)
@@ -26,6 +26,8 @@ module Droonga
   class Client
     module Connection
       class HTTP
+        attr_writer :on_error
+
         class InvalidHTTPMethodError < Error
           attr_reader :http_method
           attr_reader :request_message
@@ -179,6 +181,10 @@ module Droonga
             "#{base_path}?#{Rack::Utils.build_nested_query(parameters)}"
           end
         end
+
+        def on_error(error)
+          @on_error.call(error) if @on_error
+        end
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index