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 3, 2015
1 parent ebfbc54 commit e255e84
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ext/groonga/rb-grn-plugin.c
Expand Up @@ -121,6 +121,48 @@ rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass)
return Qnil;
}

/*
* Unregister registered plugin
*
* @overload unregister(name, options=nil)
* Unregister specified `name` plugin.
* @param [String] name The name of plugin.
* @param options [::Hash] The name and value
* pairs. Omitted context is initialized by the default one.
* @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("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
* 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.
*
Expand Down Expand Up @@ -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",
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 registered `name` plugin.
#
# Usually, `name` plugin is searched under plugin directory. If
# you want to unregister `name` plugin which is not located under
# plugin directory, specify the actual path of `name` plugin.
#
# @overload unregister_plugin(name)
# Unregister registerd plugin by name.
#
# @param [String] name The plugin name or path to plugin.
#
# @example Unregister registerd plugin by name.
# context.register_plugin("token_filters/stop_word")
# context.unregister_plugin("token_filters/stop_word")
#
# @example Unregister registerd plugin by path.
# context.register_plugin("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
# context.unregister_plugin("/usr/local/lib/groonga/plugins/token_filters/stop_word.so")
#
# @since 5.0.1
def unregister_plugin(name_or_options)
options = {:context => self}
if name_or_options.is_a?(String)
name = name_or_options
Plugin.unregister(name, options)
else
Plugin.unregister(name_or_options.merge(options))
end
end

# _table_ から指定した条件にマッチするレコードの値を取得
# する。 _table_ はテーブル名かテーブルオブジェクトを指定
# する。
Expand Down

0 comments on commit e255e84

Please sign in to comment.