[Groonga-commit] groonga/fluent-plugin-droonga at e58990d [master] Add command_mapper in order to extract common codes from handler and adapter

Back to archive index

Kosuke Asami null+****@clear*****
Mon Jul 22 16:23:36 JST 2013


Kosuke Asami	2013-07-22 16:23:36 +0900 (Mon, 22 Jul 2013)

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

  Message:
    Add command_mapper in order to extract common codes from handler and adapter

  Added files:
    lib/droonga/command_mapper.rb
    test/test_command_mapper.rb

  Added: lib/droonga/command_mapper.rb (+41 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/command_mapper.rb    2013-07-22 16:23:36 +0900 (c0fd664)
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2013 droonga project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+module Droonga
+  class CommandMapper
+    def initialize
+      @commands = {}
+    end
+
+    def register(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
+    end
+
+    def [](command)
+      @commands[command.to_s]
+    end
+  end
+end

  Added: test/test_command_mapper.rb (+29 -0) 100644
===================================================================
--- /dev/null
+++ test/test_command_mapper.rb    2013-07-22 16:23:36 +0900 (5263795)
@@ -0,0 +1,29 @@
+# Copyright (C) 2013 droonga project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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"
+
+class CommandMapperTest < Test::Unit::TestCase
+  class RegisterTest < self
+    def setup
+      @command_mapper = Droonga::CommandMapper.new
+    end
+
+    def test_name
+      @command_mapper.register(:select)
+      assert_equal(:select, @command_mapper[:select])
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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