[Groonga-commit] ranguba/rroonga at 1b782e2 [plugin-unregister] Support unregister plugin

Back to archive index

HAYASHI Kentaro null+****@clear*****
Fri Apr 3 15:20:35 JST 2015


HAYASHI Kentaro	2015-04-03 15:20:35 +0900 (Fri, 03 Apr 2015)

  New Revision: 1b782e2dff2ee0e096530a4a28a4fce634693e29
  https://github.com/ranguba/rroonga/commit/1b782e2dff2ee0e096530a4a28a4fce634693e29

  Message:
    Support unregister plugin

  Modified files:
    ext/groonga/rb-grn-plugin.c
    lib/groonga/context.rb
    test/test-plugin.rb

  Modified: ext/groonga/rb-grn-plugin.c (+44 -0)
===================================================================
--- ext/groonga/rb-grn-plugin.c    2015-04-02 18:17:22 +0900 (946805b)
+++ ext/groonga/rb-grn-plugin.c    2015-04-03 15:20:35 +0900 (f205781)
@@ -122,6 +122,48 @@ rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass)
 }
 
 /*
+ * Unregister a registered plugin.
+ *
+ * @overload unregister(name, options={})
+ *   Unregister specified `name` plugin.
+ *   You can specify the path of plugin explicitly.
+ *   @param [String] name The name of plugin.
+ *   @param options [::Hash] The name and value pairs.
+ *   @option options :context (Groonga::Context.default)
+ *     The context which is bound to database.
+ *   @example Unregister registerd plugin by name.
+ *     Groonga::Plugin.register("token_filters/stop_word")
+ *     Groonga::Plugin.unregister("token_filters/stop_word")
+ *   @example unregister registerd plugin by path
+ *     Groonga::Plugin.register("token_filters/stop_word")
+ *     Groonga::Plugin.unregister("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
+ */
+static VALUE
+rb_grn_plugin_s_unregister (int argc, VALUE *argv, VALUE klass)
+{
+    const char *name = NULL;
+    VALUE rb_options, rb_name = Qnil, rb_context;
+    grn_ctx *context;
+
+    rb_scan_args(argc, argv, "11", &rb_name, &rb_options);
+    rb_grn_scan_options(rb_options,
+                        "context", &rb_context,
+                        NULL);
+    rb_name = rb_grn_convert_to_string(rb_name);
+    name = StringValueCStr(rb_name);
+
+    if (NIL_P(rb_context)) {
+        rb_context = rb_grn_context_get_default();
+    }
+    context = RVAL2GRNCONTEXT(rb_context);
+
+    grn_plugin_unregister(context, name);
+
+    rb_grn_context_check(context, rb_ary_new4(argc, argv));
+    return Qnil;
+}
+
+/*
  * Returns the system plugins directory.
  *
  * @overload system_plugins_dir
@@ -153,6 +195,8 @@ rb_grn_init_plugin (VALUE mGrn)
 
     rb_define_singleton_method(cGrnPlugin, "register",
                                rb_grn_plugin_s_register, -1);
+    rb_define_singleton_method(cGrnPlugin, "unregister",
+                               rb_grn_plugin_s_unregister, -1);
     rb_define_singleton_method(cGrnPlugin, "system_plugins_dir",
                                rb_grn_plugin_s_system_plugins_dir, 0);
     rb_define_singleton_method(cGrnPlugin, "suffix",

  Modified: lib/groonga/context.rb (+30 -0)
===================================================================
--- lib/groonga/context.rb    2015-04-02 18:17:22 +0900 (de2d079)
+++ lib/groonga/context.rb    2015-04-03 15:20:35 +0900 (13eb8ee)
@@ -119,6 +119,36 @@ module Groonga
       end
     end
 
+    # Unregister registered `name` plugin.
+    #
+    # Usually, you can unregister `name` plugin by name if
+    # `name` plugin is installed to plugin directory.
+    #
+    # @example Unregister registerd plugin by name.
+    #   context.register_plugin("token_filters/stop_word")
+    #   context.unregister_plugin("token_filters/stop_word")
+    #
+    # You can also specify the path of `name` plugin explicitly.
+    #
+    # @example Unregister registerd plugin by path.
+    #   context.register_plugin("token_filters/stop_word")
+    #   context.unregister_plugin("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
+    #
+    # @overload unregister_plugin(name_or_path)
+    #   Unregister registerd plugin by name or by path.
+    #
+    #   @param [String] name The plugin name or path to plugin.
+    #
+    # @since 5.0.1
+    def unregister_plugin(name_or_path)
+      options = {:context => self}
+      if name_or_path.is_a?(String)
+        Plugin.unregister(name_or_path, options)
+      else
+        Plugin.unregister(name_or_path.merge(options))
+      end
+    end
+
     # _table_ から指定した条件にマッチするレコードの値を取得
     # する。 _table_ はテーブル名かテーブルオブジェクトを指定
     # する。

  Modified: test/test-plugin.rb (+3 -3)
===================================================================
--- test/test-plugin.rb    2015-04-02 18:17:22 +0900 (bd4dd02)
+++ test/test-plugin.rb    2015-04-03 15:20:35 +0900 (d2fdde3)
@@ -37,17 +37,17 @@ class PluginTest < Test::Unit::TestCase
 
   class UnregisterTest < self
     def test_by_name
-      context = Groonga::Context.default
       context.register_plugin("token_filters/stop_word")
+      assert_not_nil(context["TokenFilterStopWord"])
       context.unregister_plugin("token_filters/stop_word")
       assert_nil(context["TokenFilterStopWord"])
     end
 
     def test_by_path
-      context = Groonga::Context.default
+      context.register_plugin("token_filters/stop_word")
+      assert_not_nil(context["TokenFilterStopWord"])
       plugin_path = "#{Groonga::Plugin.system_plugins_dir}/"
       plugin_path << "token_filters/stop_word#{Groonga::Plugin.suffix}"
-      context.register_plugin(plugin_path)
       context.unregister_plugin(plugin_path)
       assert_nil(context["TokenFilterStopWord"])
     end
-------------- next part --------------
HTML����������������������������...
下载 



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