Masafumi Yokoyama
null+****@clear*****
Tue Jan 5 14:45:40 JST 2016
Masafumi Yokoyama 2016-01-05 14:45:40 +0900 (Tue, 05 Jan 2016) New Revision: e8954c4e04513503ea551442970e1e70e06d2dfa https://github.com/ranguba/rroonga/commit/e8954c4e04513503ea551442970e1e70e06d2dfa Message: Bind grn_obj_is_key_accessor() Modified files: ext/groonga/rb-grn-object.c test/test-accessor.rb Modified: ext/groonga/rb-grn-object.c (+28 -0) =================================================================== --- ext/groonga/rb-grn-object.c 2016-01-05 14:28:29 +0900 (2a93260) +++ ext/groonga/rb-grn-object.c 2016-01-05 14:45:40 +0900 (3d90909) @@ -1682,6 +1682,32 @@ rb_grn_object_accessor_p (VALUE self) return CBOOL2RVAL(accessor_p); } +/* + * Checks whether the object is key accessor or not. + * + * @overload key_accessor? + * @return [Boolean] `true` if the object is key accessor, + * `false` otherwise. + * + * @since 5.1.1 + */ +static VALUE +rb_grn_object_key_accessor_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool accessor_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + accessor_p = grn_obj_is_key_accessor(context, object); + } + + return CBOOL2RVAL(accessor_p); +} + void rb_grn_init_object (VALUE mGrn) { @@ -1729,4 +1755,6 @@ rb_grn_init_object (VALUE mGrn) rb_grn_object_scorer_procedure_p, 0); rb_define_method(rb_cGrnObject, "accessor?", rb_grn_object_accessor_p, 0); + rb_define_method(rb_cGrnObject, "key_accessor?", + rb_grn_object_key_accessor_p, 0); } Modified: test/test-accessor.rb (+15 -0) =================================================================== --- test/test-accessor.rb 2016-01-05 14:28:29 +0900 (ff851a4) +++ test/test-accessor.rb 2016-01-05 14:45:40 +0900 (ea81d80) @@ -21,6 +21,7 @@ class AccessorTest < Test::Unit::TestCase setup_database @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText") @id =****@posts*****("_id") + @key =****@posts*****("_key") end def teardown @@ -48,4 +49,18 @@ class AccessorTest < Test::Unit::TestCase end end end + + sub_test_case "#key_accessor?" do + test "true" do + assert do + @key.key_accessor? + end + end + + test "false" do + assert do + not****@id*****_accessor? + end + end + end end -------------- next part -------------- HTML����������������������������...Télécharger