Class: Groonga::Config

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

Overview

This class manages database global configurations. Each configuration is key and value pair.

Instance Method Summary collapse

Constructor Details

#initialize(context = nil) ⇒ Object

Creates a new configuration set for context.

Parameters:

Since:

  • 5.0.9



40
41
42
43
44
45
46
# File 'ext/groonga/rb-grn-config.c', line 40

static VALUE
rb_grn_config_initialize (VALUE self, VALUE rb_context)
{
    rb_iv_set(self, "@context", rb_context);

    return Qnil;
}

Instance Method Details

#configString?

Gets a configuration value for key.

Returns The value associated with key.

Parameters:

  • key (String)

    The key.

Returns:

  • (String, nil)

    The value associated with key.

Since:

  • 5.0.9



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'ext/groonga/rb-grn-config.c', line 57

static VALUE
rb_grn_config_get (VALUE self, VALUE rb_key)
{
    VALUE rb_context;
    VALUE rb_value;
    grn_ctx *context;
    const char *key;
    int key_size;
    const char *value;
    uint32_t value_size;

    rb_context = rb_iv_get(self, "@context");
    context = rb_grn_context_ensure(&rb_context);

    rb_key = rb_grn_convert_to_string(rb_key);
    key = RSTRING_PTR(rb_key);
    key_size = RSTRING_LEN(rb_key);

    {
        grn_rc rc;
        rc = grn_config_get(context,
                            key, key_size,
                            &value, &value_size);
        rb_grn_context_check(context, self);
        rb_grn_rc_check(rc, self);
    }

    if (value_size == 0) {
        rb_value = Qnil;
    } else {
        rb_value = rb_grn_context_rb_string_new(context, value, value_size);
    }

    return rb_value;
}

#configString

Sets a configuration key and value pair.

Returns value.

Parameters:

  • key (String)

    The key.

  • value (String)

    The value to be assigned.

Returns:

  • (String)

    value.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'ext/groonga/rb-grn-config.c', line 101

static VALUE
rb_grn_config_set (VALUE self, VALUE rb_key, VALUE rb_value)
{
    VALUE rb_value_original = rb_value;
    VALUE rb_context;
    grn_ctx *context;
    const char *key;
    int key_size;
    const char *value;
    int value_size;

    rb_context = rb_iv_get(self, "@context");
    context = rb_grn_context_ensure(&rb_context);

    rb_key = rb_grn_convert_to_string(rb_key);
    key = RSTRING_PTR(rb_key);
    key_size = RSTRING_LEN(rb_key);

    rb_value = rb_grn_convert_to_string(rb_value);
    value = RSTRING_PTR(rb_value);
    value_size = RSTRING_LEN(rb_value);

    {
        grn_rc rc;
        rc = grn_config_set(context,
                            key, key_size,
                            value, value_size);
        rb_grn_context_check(context, self);
        rb_grn_rc_check(rc, self);
    }

    return rb_value_original;
}

#delete(key) ⇒ Object

Deletes a configuration for key.

Parameters:

  • key (String)

    The key.

Since:

  • 6.0.0



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

static VALUE
rb_grn_config_delete (VALUE self, VALUE rb_key)
{
    VALUE rb_context;
    grn_ctx *context;
    const char *key;
    int key_size;

    rb_context = rb_iv_get(self, "@context");
    context = rb_grn_context_ensure(&rb_context);

    rb_key = rb_grn_convert_to_string(rb_key);
    key = RSTRING_PTR(rb_key);
    key_size = RSTRING_LEN(rb_key);

    {
        grn_rc rc;
        rc = grn_config_delete(context,
                               key, key_size);
        rb_grn_context_check(context, self);
        rb_grn_rc_check(rc, self);
    }

    return Qnil;
}

#each {|key, value| ... } ⇒ Object

Passes all key/value of the config to block in order.

Examples:

Shows all keys and all values of the config

context.config["rroonga.key1"] = "value1"
context.config["rroonga.key2"] = "value2"
keys = []
values = []
context.config.each do |key, value|
  keys << key
  values << value
end
p keys   # => ["rroonga.key1", "rroonga.key2"]
p values # => ["value1", "value2"]

Yields:

  • (key, value)

Yield Parameters:

  • key (String)

    The configuration key

  • value (String)

    The value which is associated with key

Since:

  • 6.0.0



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'ext/groonga/rb-grn-config.c', line 234

static VALUE
rb_grn_config_each (VALUE self)
{
    VALUE rb_context;
    RbGrnConfigEachData data;

    RETURN_ENUMERATOR(self, 0, NULL);

    rb_context = rb_iv_get(self, "@context");
    data.context = rb_grn_context_ensure(&rb_context);

    data.cursor = grn_config_cursor_open(data.context);
    rb_ensure(rb_grn_config_each_body, (VALUE)&data,
              rb_grn_config_each_ensure, (VALUE)&data);

    return Qnil;
}