-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bind grn_config_delete() #119
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} |
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,13 @@ 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 do | ||
not context.config["rroonga.key"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 勘違いしました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've fixed it. |
||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it.