[Groonga-commit] groonga/groonga-schema at 3abd0d0 [master] Support plugin

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Mon Aug 8 14:26:23 JST 2016


Kouhei Sutou	2016-08-08 14:26:23 +0900 (Mon, 08 Aug 2016)

  New Revision: 3abd0d064c4bb52421dfd5ffa68c8e45b66cc61c
  https://github.com/groonga/groonga-schema/commit/3abd0d064c4bb52421dfd5ffa68c8e45b66cc61c

  Message:
    Support plugin

  Copied files:
    lib/groonga-schema/plugin.rb
      (from lib/groonga-schema/schema.rb)
    test/test-plugin.rb
      (from lib/groonga-schema/schema.rb)
  Modified files:
    lib/groonga-schema/schema.rb
    test/test-schema.rb

  Copied: lib/groonga-schema/plugin.rb (+8 -23) 55%
===================================================================
--- lib/groonga-schema/schema.rb    2016-08-08 13:42:45 +0900 (bad0dd2)
+++ lib/groonga-schema/plugin.rb    2016-08-08 14:26:23 +0900 (702f3d4)
@@ -14,32 +14,17 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "groonga-schema/table"
-require "groonga-schema/column"
-
 module GroongaSchema
-  class Schema
-    attr_reader :plugins
-    attr_reader :tables
-    attr_reader :columns
-    def initialize
-      @plugins = []
-      @tables = {}
-      @columns = {}
+  class Plugin
+    attr_reader :name
+    def initialize(name)
+      @name = name
     end
 
-    def apply_command(command)
-      case command.command_name
-      when "table_create"
-        table = Table.new(command.name)
-        table.apply_command(command)
-        @tables[table.name] = table
-      when "column_create"
-        column = Column.new(command.table, command.name)
-        column.apply_command(command)
-        @columns[column.table_name] ||= {}
-        @columns[column.table_name][column.name] = column
-      end
+    def ==(other)
+      return false unless other.is_a?(self.class)
+
+      @name == other.name
     end
   end
 end

  Modified: lib/groonga-schema/schema.rb (+8 -1)
===================================================================
--- lib/groonga-schema/schema.rb    2016-08-08 13:42:45 +0900 (bad0dd2)
+++ lib/groonga-schema/schema.rb    2016-08-08 14:26:23 +0900 (06df9e6)
@@ -14,8 +14,9 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "groonga-schema/table"
 require "groonga-schema/column"
+require "groonga-schema/plugin"
+require "groonga-schema/table"
 
 module GroongaSchema
   class Schema
@@ -30,6 +31,12 @@ module GroongaSchema
 
     def apply_command(command)
       case command.command_name
+      when "register"
+        plugin = Plugin.new(command.path)
+        @plugins << plugin
+      when "plugin_register"
+        plugin = Plugin.new(command.name)
+        @plugins << plugin
       when "table_create"
         table = Table.new(command.name)
         table.apply_command(command)

  Copied: test/test-plugin.rb (+10 -24) 54%
===================================================================
--- lib/groonga-schema/schema.rb    2016-08-08 13:42:45 +0900 (bad0dd2)
+++ test/test-plugin.rb    2016-08-08 14:26:23 +0900 (f2b91de)
@@ -14,32 +14,18 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "groonga-schema/table"
-require "groonga-schema/column"
-
-module GroongaSchema
-  class Schema
-    attr_reader :plugins
-    attr_reader :tables
-    attr_reader :columns
-    def initialize
-      @plugins = []
-      @tables = {}
-      @columns = {}
+class PluginTest < Test::Unit::TestCase
+  sub_test_case "#==" do
+    test "equal" do
+      plugin1 = GroongaSchema::Plugin.new("token_filters/stem")
+      plugin2 = GroongaSchema::Plugin.new("token_filters/stem")
+      assert_equal(plugin1, plugin2)
     end
 
-    def apply_command(command)
-      case command.command_name
-      when "table_create"
-        table = Table.new(command.name)
-        table.apply_command(command)
-        @tables[table.name] = table
-      when "column_create"
-        column = Column.new(command.table, command.name)
-        column.apply_command(command)
-        @columns[column.table_name] ||= {}
-        @columns[column.table_name][column.name] = column
-      end
+    test "not equal" do
+      plugin1 = GroongaSchema::Plugin.new("token_filters/stem")
+      plugin2 = GroongaSchema::Plugin.new("token_filters/stop_word")
+      assert_not_equal(plugin1, plugin2)
     end
   end
 end

  Modified: test/test-schema.rb (+24 -0)
===================================================================
--- test/test-schema.rb    2016-08-08 13:42:45 +0900 (5f029fb)
+++ test/test-schema.rb    2016-08-08 14:26:23 +0900 (13067e3)
@@ -19,6 +19,14 @@ class SchemaTest < Test::Unit::TestCase
     @schema = GroongaSchema::Schema.new
   end
 
+  def register(arguments)
+    Groonga::Command::Register.new(arguments)
+  end
+
+  def plugin_register(arguments)
+    Groonga::Command::PluginRegister.new(arguments)
+  end
+
   def table_create(arguments)
     Groonga::Command::TableCreate.new(arguments)
   end
@@ -28,6 +36,22 @@ class SchemaTest < Test::Unit::TestCase
   end
 
   sub_test_case "#apply_command" do
+    test "plugin - register" do
+      command = register("path" => "token_filters/stem")
+      @schema.apply_command(command)
+
+      assert_equal(["token_filters/stem"],
+                   @schema.plugins.collect(&:name))
+    end
+
+    test "plugin - plugin_register" do
+      command = plugin_register("name" => "token_filters/stem")
+      @schema.apply_command(command)
+
+      assert_equal(["token_filters/stem"],
+                   @schema.plugins.collect(&:name))
+    end
+
     test "lexicon" do
       arguments = {
         "name"              => "Words",
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index