Class: Groonga::Plugin

Inherits:
Object
  • Object
show all
Defined in:
ext/groonga/rb-grn-plugin.c,
ext/groonga/rb-grn-plugin.c

Overview

プラグイン。現在のところ、Rubyでgroongaのプラグインを作成 することはできず、Cで作成された既存のプラグインを登録する ことができるだけです。

Class Method Summary collapse

Class Method Details

.names(options = {}) ⇒ Array<String>

Returns the names of loaded plugins.

Parameters:

  • options (::Hash) (defaults to: {})

    The name and value pairs.

Options Hash (options):

  • :context (Object) — default: Groonga::Context.default

    The context which is bound to database.

Returns:

Since:

  • 6.0.0



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/groonga/rb-grn-plugin.c', line 220

static VALUE
rb_grn_plugin_s_names (int argc, VALUE *argv, VALUE klass)
{
    VALUE rb_options, rb_context, rb_names;
    grn_ctx *context;
    grn_obj names;

    rb_scan_args(argc, argv, "01", &rb_options);
    rb_grn_scan_options(rb_options,
                        "context", &rb_context,
                        NULL);
    if (NIL_P(rb_context)) {
        rb_context = rb_grn_context_get_default();
    }
    context = RVAL2GRNCONTEXT(rb_context);

    GRN_TEXT_INIT(&names, GRN_OBJ_VECTOR);
    grn_plugin_get_names(context, &names);
    rb_names = GRNVECTOR2RVAL(context, &names);
    GRN_OBJ_FIN(context, &names);

    rb_grn_context_check(context, rb_ary_new_from_values(argc, argv));
    return rb_names;
}

.register(name, options = nil) ⇒ Object .register({: path => path, :context => nil}) ⇒ Object

既存のプラグインをデータベースに登録する。

Overloads:

  • .register(name, options = nil) ⇒ Object

    name で指定した名前のプラグインを登録する。

    Parameters:

    • name (String)

      登録するプラグインの名前

    • options (::Hash) (defaults to: nil)

      The name and value pairs. Omitted names are initialized as the default value.

    Options Hash (options):

    • :context (Object) — default: Groonga::Context.default

      データベースを結びつけるコンテキスト。

  • .register({: path => path, :context => nil}) ⇒ Object

    :path で指定したパスのプラグインを登録する。

    :context については name を設定した時と同様。

    Parameters:

    • hash (::Hash)

      :path:context を指定したハッシュを指定する。



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'ext/groonga/rb-grn-plugin.c', line 84

static VALUE
rb_grn_plugin_s_register (int argc, VALUE *argv, VALUE klass)
{
    const char *name = NULL, *path = NULL;
    VALUE rb_options, rb_name = Qnil, rb_path, rb_context;
    grn_ctx *context;

    if (argc >= 1) {
        rb_name = rb_grn_check_convert_to_string(argv[0]);
    }

    if (NIL_P(rb_name)) {
        rb_scan_args(argc, argv, "01", &rb_options);
        rb_grn_scan_options(rb_options,
                            "path", &rb_path,
                            "context", &rb_context,
                            NULL);
        path = StringValueCStr(rb_path);
    } else {
        rb_scan_args(argc, argv, "11", &rb_name, &rb_options);
        rb_grn_scan_options(rb_options,
                            "context", &rb_context,
                            NULL);
        name = StringValueCStr(rb_name);
    }

    if (NIL_P(rb_context)) {
        rb_context = rb_grn_context_get_default();
    }
    context = RVAL2GRNCONTEXT(rb_context);

    if (name) {
        grn_plugin_register(context, name);
    } else {
        grn_plugin_register_by_path(context, path);
    }

    rb_grn_context_check(context, rb_ary_new_from_values(argc, argv));
    return Qnil;
}

.ruby_suffixString

Returns the plugin file suffix written in Ruby. It returns “.rb”.

Returns:

  • (String)

Since:

  • 5.0.2



203
204
205
206
207
# File 'ext/groonga/rb-grn-plugin.c', line 203

static VALUE
rb_grn_plugin_s_ruby_suffix (VALUE klass)
{
    return rb_str_new_cstr(grn_plugin_get_ruby_suffix());
}

.suffixString

Returns the plugin file suffix. (e.g. “.so”, “.dll” and so on.)

Returns:

  • (String)


189
190
191
192
193
# File 'ext/groonga/rb-grn-plugin.c', line 189

static VALUE
rb_grn_plugin_s_suffix (VALUE klass)
{
    return rb_str_new_cstr(grn_plugin_get_suffix());
}

.system_plugins_dirString

Returns the system plugins directory.

Returns:

  • (String)


177
178
179
180
181
# File 'ext/groonga/rb-grn-plugin.c', line 177

static VALUE
rb_grn_plugin_s_system_plugins_dir (VALUE klass)
{
    return rb_str_new_cstr(grn_plugin_get_system_plugins_dir());
}

.unregister(name, options = {}) ⇒ Object

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.

Examples:

Unregister a registerd plugin by name.

Groonga::Plugin.register("token_filters/stop_word")
Groonga::Plugin.unregister("token_filters/stop_word")

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")

Unregister specified name plugin. You can specify the path of plugin explicitly.

Parameters:

  • name (String)

    The name of plugin.

  • options (::Hash) (defaults to: {})

    The name and value pairs.

Options Hash (options):

  • :context (Object) — default: Groonga::Context.default

    The context which is bound to database.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/groonga/rb-grn-plugin.c', line 146

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_new_from_values(argc, argv));
    return Qnil;
}