[Groonga-commit] ranguba/rroonga at cdd6773 [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: cdd67731c9d2429c56eaa633497177a175ce3299
  https://github.com/ranguba/rroonga/commit/cdd67731c9d2429c56eaa633497177a175ce3299

  Message:
    Support unregister plugin

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

  Modified: ext/groonga/rb-grn-plugin.c (+48 -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 (d1b904b)
@@ -122,6 +122,52 @@ rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass)
 }
 
 /*
+ * Unregister a registered plugin.
+ *
+ * Unregister `name` plugin by name if `name` plugin is installed to
+ * plugin directory. You can also specify the path of `name` plugin
+ * explicitly.
+ *
+ * @example Unregister a registerd plugin by name.
+ *   Groonga::Plugin.register("token_filters/stop_word")
+ *   Groonga::Plugin.unregister("token_filters/stop_word")
+ * @example unregister a registerd plugin by path
+ *   Groonga::Plugin.register("token_filters/stop_word")
+ *   Groonga::Plugin.unregister("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
+ * @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.
+ */
+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 +199,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 (e0b12d4)
@@ -119,6 +119,36 @@ module Groonga
       end
     end
 
+    # Unregister a registered `name` plugin.
+    #
+    # You can unregister `name` plugin by name if
+    # `name` plugin is installed to plugin directory.
+    #
+    # @example Unregister a 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 a 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 a 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_ はテーブル名かテーブルオブジェクトを指定
     # する。
-------------- next part --------------
HTML����������������������������...
下载 



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