Navigation Menu

Skip to content

Commit

Permalink
Support unregister plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kenhys committed Apr 8, 2015
1 parent 3ef8a4e commit cdd6773
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ext/groonga/rb-grn-plugin.c
Expand Up @@ -121,6 +121,52 @@ rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass)
return Qnil;
}

/*
* 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.
*
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions lib/groonga/context.rb
Expand Up @@ -119,6 +119,36 @@ def register_plugin(name_or_options)
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_ はテーブル名かテーブルオブジェクトを指定
# する。
Expand Down

0 comments on commit cdd6773

Please sign in to comment.