Kouhei Sutou
null+****@clear*****
Tue Apr 14 18:20:12 JST 2015
Kouhei Sutou 2015-04-14 18:20:12 +0900 (Tue, 14 Apr 2015) New Revision: 8681e69d01d3ab9384f38a7f6e85f7036035acfd https://github.com/ranguba/rroonga/commit/8681e69d01d3ab9384f38a7f6e85f7036035acfd Message: Add object type predicates Modified files: ext/groonga/rb-grn-object.c test/test-column.rb test/test-procedure.rb test/test-table.rb Modified: ext/groonga/rb-grn-object.c (+136 -0) =================================================================== --- ext/groonga/rb-grn-object.c 2015-04-14 18:11:56 +0900 (ea4fc6c) +++ ext/groonga/rb-grn-object.c 2015-04-14 18:20:12 +0900 (be8d879) @@ -1502,6 +1502,134 @@ rb_grn_object_builtin_p (VALUE self) return CBOOL2RVAL(builtin); } +/* + * Checks whether the object is table or not. + * + * @overload table? + * @return [Boolean] `true` if the object is table, `false` otherwise. + * + * @since 5.0.1 + */ +static VALUE +rb_grn_object_table_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool table_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + table_p = grn_obj_is_table(context, object); + } + + return CBOOL2RVAL(table_p); +} + +/* + * Checks whether the object is procedure or not. + * + * @overload procedure? + * @return [Boolean] `true` if the object is procedure, `false` otherwise. + * + * @since 5.0.1 + */ +static VALUE +rb_grn_object_procedure_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool procedure_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + procedure_p = grn_obj_is_proc(context, object); + } + + return CBOOL2RVAL(procedure_p); +} + +/* + * Checks whether the object is function procedure or not. + * + * @overload function_procedure? + * @return [Boolean] `true` if the object is function procedure, + * `false` otherwise. + * + * @since 5.0.1 + */ +static VALUE +rb_grn_object_function_procedure_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool function_procedure_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + function_procedure_p = grn_obj_is_function_proc(context, object); + } + + return CBOOL2RVAL(function_procedure_p); +} + +/* + * Checks whether the object is selector procedure or not. + * + * @overload selector_procedure? + * @return [Boolean] `true` if the object is selector procedure, + * `false` otherwise. + * + * @since 5.0.1 + */ +static VALUE +rb_grn_object_selector_procedure_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool selector_procedure_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + selector_procedure_p = grn_obj_is_selector_proc(context, object); + } + + return CBOOL2RVAL(selector_procedure_p); +} + +/* + * Checks whether the object is scorer procedure or not. + * + * @overload scorer_procedure? + * @return [Boolean] `true` if the object is scorer procedure, + * `false` otherwise. + * + * @since 5.0.1 + */ +static VALUE +rb_grn_object_scorer_procedure_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool scorer_procedure_p = GRN_FALSE; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + + if (context && object) { + scorer_procedure_p = grn_obj_is_scorer_proc(context, object); + } + + return CBOOL2RVAL(scorer_procedure_p); +} + void rb_grn_init_object (VALUE mGrn) { @@ -1537,4 +1665,12 @@ rb_grn_init_object (VALUE mGrn) rb_define_method(rb_cGrnObject, "remove", rb_grn_object_remove, 0); rb_define_method(rb_cGrnObject, "builtin?", rb_grn_object_builtin_p, 0); + rb_define_method(rb_cGrnObject, "table?", rb_grn_object_table_p, 0); + rb_define_method(rb_cGrnObject, "procedure?", rb_grn_object_procedure_p, 0); + rb_define_method(rb_cGrnObject, "function_procedure?", + rb_grn_object_function_procedure_p, 0); + rb_define_method(rb_cGrnObject, "selector_procedure?", + rb_grn_object_selector_procedure_p, 0); + rb_define_method(rb_cGrnObject, "scorer_procedure?", + rb_grn_object_scorer_procedure_p, 0); } Modified: test/test-column.rb (+6 -0) =================================================================== --- test/test-column.rb 2015-04-14 18:11:56 +0900 (43fd4b0) +++ test/test-column.rb 2015-04-14 18:20:12 +0900 (216dc20) @@ -340,6 +340,12 @@ class ColumnTest < Test::Unit::TestCase assert_not_predicate(@users_name_column, :builtin?) end + def test_table? + assert do + not @users_name_column.table? + end + end + private def assert_content_search(expected_records, term) records = @bookmarks_index_content.search(term).records Modified: test/test-procedure.rb (+24 -0) =================================================================== --- test/test-procedure.rb 2015-04-14 18:11:56 +0900 (56cf1c5) +++ test/test-procedure.rb 2015-04-14 18:20:12 +0900 (9374baa) @@ -27,6 +27,30 @@ class ProcedureTest < Test::Unit::TestCase :accept_nil => true) end + def test_procedure? + assert do + Groonga["TokenBigram"].procedure? + end + end + + def test_function_procedure? + assert do + Groonga["rand"].function_procedure? + end + end + + def test_selector_procedure? + assert do + Groonga["between"].selector_procedure? + end + end + + def test_scorer_procedure? + assert do + Groonga["scorer_tf_idf"].scorer_procedure? + end + end + private def assert_equal_procedure(expected_name, id, options={}) procedure = Groonga::Context.default[id] Modified: test/test-table.rb (+7 -0) =================================================================== --- test/test-table.rb 2015-04-14 18:11:56 +0900 (8d96a6d) +++ test/test-table.rb 2015-04-14 18:20:12 +0900 (32a208d) @@ -630,6 +630,13 @@ class TableTest < Test::Unit::TestCase assert_not_predicate(bookmarks, :builtin?) end + def test_table? + bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks") + assert do + bookmarks.table? + end + end + class OtherProcessTest < self def test_create by_other_process do -------------- next part -------------- HTML����������������������������... 다운로드