Skip to content
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

Merged
merged 3 commits into from
Mar 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ext/groonga/rb-grn-config.c
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
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent is broken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it.

rb_grn_context_check(context, self);
rb_grn_rc_check(rc, self);
}

return Qnil;
}

void
rb_grn_init_config (VALUE mGrn)
{
Expand All @@ -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);
}
10 changes: 10 additions & 0 deletions test/test-config.rb
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
Expand Down Expand Up @@ -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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not assert_nil(context.config["rroonga.key"])?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

勘違いしました。
真偽値のチェックにはassert do 〜 endを使うべきと思っていましたが、
ここはnilかどうかなので真偽値ではないですね。修正します。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it.

end
end
end