[Groonga-commit] droonga/droonga-client-ruby at 4a58b5b [master] Allow to enable/disable completion and validation for each message

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Jan 16 18:37:50 JST 2015


YUKI Hiroshi	2015-01-16 18:37:50 +0900 (Fri, 16 Jan 2015)

  New Revision: 4a58b5b186ebc52f9d9ec7bec196f5f9afb8b9d5
  https://github.com/droonga/droonga-client-ruby/commit/4a58b5b186ebc52f9d9ec7bec196f5f9afb8b9d5

  Message:
    Allow to enable/disable completion and validation for each message

  Modified files:
    lib/droonga/client.rb

  Modified: lib/droonga/client.rb (+30 -12)
===================================================================
--- lib/droonga/client.rb    2015-01-16 17:39:46 +0900 (da7dc3b)
+++ lib/droonga/client.rb    2015-01-16 18:37:50 +0900 (d4f3704)
@@ -68,29 +68,29 @@ module Droonga
     #   Do or do not validate input messages.
     def initialize(options={})
       @connection = create_connection(options)
-      unless options[:completion] == false
-        @completer = MessageCompleter.new
-      end
-      unless options[:validation] == false
-        @validator = MessageValidator.new
-      end
+
+      @completion = options[:completion] != false
+      @validation = options[:validation] != false
+
+      @completer = MessageCompleter.new
+      @validator = MessageValidator.new
     end
 
     def send(message, options={}, &block)
-      message =****@compl*****(message) if @completer
-      @validator.validate(message) if @validator
+      message = do_completion(message, options)
+      do_validation(message, options)
       @connection.send(message, options, &block)
     end
 
     def request(message, options={}, &block)
-      message =****@compl*****(message) if @completer
-      @validator.validate(message) if @validator
+      message = do_completion(message, options)
+      do_validation(message, options)
       @connection.request(message, options, &block)
     end
 
     def subscribe(message, options={}, &block)
-      message =****@compl*****(message) if @completer
-      @validator.validate(message) if @validator
+      message = do_completion(message, options)
+      do_validation(message, options)
       @connection.subscribe(message, options, &block)
     end
 
@@ -111,5 +111,23 @@ module Droonga
         Connection::DroongaProtocol.new(options)
       end
     end
+
+    def do_completion(message, options={})
+      if options[:completion].nil?
+        return message unless @completion
+      else
+        return message if options[:completion] == false
+      end
+      @completer.complete(message)
+    end
+
+    def do_validation(message, options={})
+      if options[:validation].nil?
+        return unless @validation
+      else
+        return if options[:validation] == false
+      end
+      @validator.validate(message)
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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