Masafumi Yokoyama
null+****@clear*****
Sat Mar 5 22:49:42 JST 2016
Masafumi Yokoyama 2016-03-05 22:49:42 +0900 (Sat, 05 Mar 2016) New Revision: adaaa92e361c058e34becd9fa52e6bce6b3a3b9a https://github.com/ranguba/rroonga/commit/adaaa92e361c058e34becd9fa52e6bce6b3a3b9a Message: Bind grn_obj_type_to_string() GitHub: #116 Modified files: ext/groonga/rb-grn-object.c test/test-database.rb test/test-hash.rb Modified: ext/groonga/rb-grn-object.c (+31 -0) =================================================================== --- ext/groonga/rb-grn-object.c 2016-03-05 22:56:03 +0900 (2f20c25) +++ ext/groonga/rb-grn-object.c 2016-03-05 22:49:42 +0900 (8d4a584) @@ -1718,6 +1718,34 @@ rb_grn_object_key_accessor_p (VALUE self) return CBOOL2RVAL(key_accessor_p); } +/** + * Returns the object type string. + * + * @example Groonga::Database + * Groonga::Database.create(:path => "/path/to/db") do |database| + * p database.type_string # => "db" + * end + * + * @example Groonga::Hash + * users = Groonga::Hash.create(:name => "Users") + * p users.type_string # => "table:hash_key" + * + * @overload type_string + * @return [String] The object type string. + * + * @since 6.0.0 + */ +static VALUE +rb_grn_object_type_to_string (VALUE self) +{ + grn_obj *object; + + rb_grn_object_deconstruct(SELF(self), &object, NULL, + NULL, NULL, NULL, NULL); + + return rb_str_new_cstr(grn_obj_type_to_string(object->header.type)); +} + void rb_grn_init_object (VALUE mGrn) { @@ -1767,4 +1795,7 @@ rb_grn_init_object (VALUE mGrn) rb_grn_object_accessor_p, 0); rb_define_method(rb_cGrnObject, "key_accessor?", rb_grn_object_key_accessor_p, 0); + + rb_define_method(rb_cGrnObject, "type_string", + rb_grn_object_type_to_string, 0); } Modified: test/test-database.rb (+6 -0) =================================================================== --- test/test-database.rb 2016-03-05 22:56:03 +0900 (638c4d0) +++ test/test-database.rb 2016-03-05 22:49:42 +0900 (f018308) @@ -276,6 +276,12 @@ class DatabaseTest < Test::Unit::TestCase terms.collect(&:_key).sort) end + def test_type_string + Groonga::Database.create(:path => @database_path.to_s) do |database| + assert_equal("db", database.type_string) + end + end + class RemoveTest < self setup :setup_database Modified: test/test-hash.rb (+6 -1) =================================================================== --- test/test-hash.rb 2016-03-05 22:56:03 +0900 (3a4b27e) +++ test/test-hash.rb 2016-03-05 22:49:42 +0900 (04c7d32) @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2014 Masafumi Yokoyama <myokoym �� gmail.com> # Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2014-2016 Masafumi Yokoyama <yokoyama �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -443,4 +443,9 @@ class HashTest < Test::Unit::TestCase user_names = users.each.collect(&:key) assert_equal(["Alice", "Bob", "Carl"], user_names) end + + def test_type_string + users = Groonga::Hash.create(:name => "Users") + assert_equal("table:hash_key", users.type_string) + end end -------------- next part -------------- HTML����������������������������...Download