Hiroshi Hatake
null+****@clear*****
Mon Dec 29 01:49:23 JST 2014
Hiroshi Hatake 2014-12-29 01:49:23 +0900 (Mon, 29 Dec 2014) New Revision: d11fdd518a8a72e8e81845cee5ceeb17d2c799c8 https://github.com/ranguba/rroonga/commit/d11fdd518a8a72e8e81845cee5ceeb17d2c799c8 Merged 337887e: Merge pull request #41 from cosmo0920/bind-column-truncate Message: Bind grn_column_truncate() that is exported since Groonga 4.0.9 Modified files: ext/groonga/rb-grn-column.c test/test-column.rb Modified: ext/groonga/rb-grn-column.c (+26 -0) =================================================================== --- ext/groonga/rb-grn-column.c 2014-12-30 08:05:09 +0900 (3ee76dc) +++ ext/groonga/rb-grn-column.c 2014-12-29 01:49:23 +0900 (040a7b0) @@ -609,6 +609,31 @@ rb_grn_column_reference_p (VALUE self) } /* + * Remove all column at once. + * + * @since 4.0.8 + * + * @overload truncate + */ +static VALUE +rb_grn_column_truncate (VALUE self) +{ + grn_ctx *context; + grn_obj *column; + grn_rc rc; + + rb_grn_column_deconstruct(SELF(self), &column, &context, + NULL, NULL, + NULL, NULL, NULL); + rc = grn_column_truncate(context, column); + + rb_grn_context_check(context, self); + rb_grn_rc_check(rc, self); + + return Qnil; +} + +/* * _column_ が {Groonga::IndexColumn} の場合は +true+ を返し、 * そうでない場合は +false+ を返す。 * @@ -802,6 +827,7 @@ rb_grn_init_column (VALUE mGrn) rb_define_method(rb_cGrnColumn, "clear_lock", rb_grn_column_clear_lock, -1); rb_define_method(rb_cGrnColumn, "locked?", rb_grn_column_is_locked, -1); rb_define_method(rb_cGrnColumn, "reference?", rb_grn_column_reference_p, 0); + rb_define_method(rb_cGrnColumn, "truncate", rb_grn_column_truncate, 0); /* deprecated: backward compatibility */ rb_define_alias(rb_cGrnColumn, "reference_column?", "reference?"); rb_define_method(rb_cGrnColumn, "index?", rb_grn_column_index_p, 0); Modified: test/test-column.rb (+25 -0) =================================================================== --- test/test-column.rb 2014-12-30 08:05:09 +0900 (c1f88b9) +++ test/test-column.rb 2014-12-29 01:49:23 +0900 (8fc0a6b) @@ -518,4 +518,29 @@ class ColumnTest < Test::Unit::TestCase assert_nil(@users.column("name")) end end + + class TruncateTest < self + def setup + setup_database + + end + def test_truncate + posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText") + posts.define_column("article", "Text") + article = "This is test." + post1 = posts.add("hello1", :article => article) + post2 = posts.add("hello2", :article => article) + + assert_equal(article, post1["article"]) + assert_equal(article, post2["article"]) + + @posts = context["Posts"] + assert_nothing_raised do + @posts.column("article").truncate + end + + assert_nil(post1["article"]) + assert_nil(post2["article"]) + end + end end -------------- next part -------------- HTML����������������������������... 下载