[Groonga-commit] groonga/fluent-plugin-droonga at d124d65 [master] Use command_mapper in order to manage command

Back to archive index

Kosuke Asami null+****@clear*****
Mon Jul 22 16:50:24 JST 2013


Kosuke Asami	2013-07-22 16:50:24 +0900 (Mon, 22 Jul 2013)

  New Revision: d124d65b3bce88d111ea4add7a7ef30c63ecbbc6
  https://github.com/groonga/fluent-plugin-droonga/commit/d124d65b3bce88d111ea4add7a7ef30c63ecbbc6

  Message:
    Use command_mapper in order to manage command

  Modified files:
    lib/droonga/adapter.rb
    lib/droonga/handler.rb

  Modified: lib/droonga/adapter.rb (+5 -12)
===================================================================
--- lib/droonga/adapter.rb    2013-07-22 16:48:45 +0900 (ed779c8)
+++ lib/droonga/adapter.rb    2013-07-22 16:50:24 +0900 (1c73ac6)
@@ -15,29 +15,22 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+require "droonga/command_mapper"
+
 module Droonga
   class Adapter
     class << self
       def inherited(sub_class)
         super
-        sub_class.instance_variable_set(:@commands, {})
+        sub_class.instance_variable_set(:@command_mapper, CommandMapper.new)
       end
 
       def command(name_or_map)
-        if name_or_map.is_a?(Hash)
-          command_map = name_or_map
-          command_map.each do |command_name, method_name|
-            @commands[command_name.to_s] = method_name
-          end
-        else
-          name = name_or_map
-          method_name = name
-          @commands[name.to_s] = method_name
-        end
+        @command_mapper.register(name_or_map)
       end
 
       def method_name(command)
-        @commands[command.to_s]
+        @command_mapper[command]
       end
     end
 

  Modified: lib/droonga/handler.rb (+4 -12)
===================================================================
--- lib/droonga/handler.rb    2013-07-22 16:48:45 +0900 (7c5f241)
+++ lib/droonga/handler.rb    2013-07-22 16:50:24 +0900 (15500a8)
@@ -16,30 +16,22 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 require "droonga/handler_plugin"
+require "droonga/command_mapper"
 
 module Droonga
   class Handler
     class << self
       def inherited(sub_class)
         super
-        sub_class.instance_variable_set(:@commands, {})
+        sub_class.instance_variable_set(:@command_mapper, CommandMapper.new)
       end
 
       def command(name_or_map)
-        if name_or_map.is_a?(Hash)
-          command_map = name_or_map
-          command_map.each do |command_name, method_name|
-            @commands[command_name.to_s] = method_name
-          end
-        else
-          name = name_or_map
-          method_name = name
-          @commands[name.to_s] = method_name
-        end
+        @command_mapper.register(name_or_map)
       end
 
       def method_name(command)
-        @commands[command.to_s]
+        @command_mapper[command]
       end
 
       def handlable?(command)
-------------- next part --------------
HTML����������������������������...
Download 



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