HAYASHI Kentaro
null+****@clear*****
Thu Apr 2 19:08:43 JST 2015
HAYASHI Kentaro 2015-04-02 19:08:43 +0900 (Thu, 02 Apr 2015) New Revision: af0e4e42ecb7decee75d146435d0c0caf16bbf78 https://github.com/ranguba/rroonga/commit/af0e4e42ecb7decee75d146435d0c0caf16bbf78 Message: Support plugin unregister Modified files: ext/groonga/rb-grn-plugin.c lib/groonga/context.rb Modified: ext/groonga/rb-grn-plugin.c (+42 -0) =================================================================== --- ext/groonga/rb-grn-plugin.c 2015-04-02 18:57:10 +0900 (946805b) +++ ext/groonga/rb-grn-plugin.c 2015-04-02 19:08:43 +0900 (3fa6474) @@ -122,6 +122,46 @@ rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass) } /* + * Unregister already 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 names are initialized as the default value. + * @option options :context (Groonga::Context.default) + * The context which is bound to database. + * @example Unregister already registerd plugin by name + * Plugin.unregister("token_filters/stop_word") + * @example unregister already registerd plugin by path + * 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 +193,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 (+26 -0) =================================================================== --- lib/groonga/context.rb 2015-04-02 18:57:10 +0900 (de2d079) +++ lib/groonga/context.rb 2015-04-02 19:08:43 +0900 (6494520) @@ -119,6 +119,32 @@ module Groonga end end + # Unregister already registered `name` plugin + # If path is specified, you can unregister plugin + # which isn't placed at plugin directory. + # + # @overload unregister_plugin(name) + # Unregister already registerd plugin by name + # + # @param [String] name The plugin name or path to plugin. + # + # @example Unregister already registerd plugin by name + # unregister_plugin("token_filters/stop_word") + # + # @example unregister already registerd plugin by path + # 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_ はテーブル名かテーブルオブジェクトを指定 # する。 -------------- next part -------------- HTML����������������������������...Download