-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from ranguba/bind-grn_config_delete
Bind grn_config_delete() Patch by Masafumi Yokoyama. Thanks!!!
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
/* | ||
Copyright (C) 2015-2016 Kouhei Sutou <[email protected]> | ||
Copyright (C) 2016 Masafumi Yokoyama <[email protected]> | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
|
@@ -131,6 +132,40 @@ rb_grn_config_set (VALUE self, VALUE rb_key, VALUE rb_value) | |
return rb_value_original; | ||
} | ||
|
||
/* | ||
* Deletes a configuration for key. | ||
* | ||
* @overload delete(key) | ||
* @param [String] key The key. | ||
* | ||
* @since 6.0.0 | ||
*/ | ||
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; | ||
} | ||
|
||
void | ||
rb_grn_init_config (VALUE mGrn) | ||
{ | ||
|
@@ -143,4 +178,6 @@ rb_grn_init_config (VALUE mGrn) | |
|
||
rb_define_method(cGrnConfig, "[]", rb_grn_config_get, 1); | ||
rb_define_method(cGrnConfig, "[]=", rb_grn_config_set, 2); | ||
|
||
rb_define_method(cGrnConfig, "delete", rb_grn_config_delete, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright (C) 2015-2016 Kouhei Sutou <[email protected]> | ||
# Copyright (C) 2016 Masafumi Yokoyama <[email protected]> | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
|
@@ -28,4 +29,11 @@ class ConfigTest < Test::Unit::TestCase | |
assert_nil(context.config["nonexistent"]) | ||
end | ||
end | ||
|
||
test "#delete" do | ||
context.config["rroonga.key"] = "value" | ||
assert_equal("value", context.config["rroonga.key"]) | ||
context.config.delete("rroonga.key") | ||
assert_nil(context.config["rroonga.key"]) | ||
end | ||
end |