Masafumi Yokoyama
null+****@clear*****
Mon Jul 13 10:26:58 JST 2015
Masafumi Yokoyama 2015-07-13 10:26:58 +0900 (Mon, 13 Jul 2015) New Revision: 1a34589d5e68b22ef2dcc1fa1799070cb0e01782 https://github.com/ranguba/rroonga/commit/1a34589d5e68b22ef2dcc1fa1799070cb0e01782 Message: Support :recursive option for Flushable#flush Modified files: ext/groonga/rb-grn-flushable.c test/test-flushable.rb Modified: ext/groonga/rb-grn-flushable.c (+21 -3) =================================================================== --- ext/groonga/rb-grn-flushable.c 2015-07-10 18:15:05 +0900 (d9f927f) +++ ext/groonga/rb-grn-flushable.c 2015-07-13 10:26:58 +0900 (27b2fd3) @@ -29,13 +29,27 @@ /* * Flush memory mapped data to disk. * - * @return [void] + * @overload flush(options={}) + * @param [::Hash] options + * @option options [Boolean] :recursive (true) Whether to flush objects + * which a target object has recursively. + * @return [void] */ static VALUE -rb_grn_flushable_flush (VALUE self) +rb_grn_flushable_flush (int argc, VALUE *argv, VALUE self) { grn_ctx *context = NULL; grn_obj *object = NULL; + VALUE rb_recursive_p; + VALUE rb_options; + + rb_scan_args(argc, argv, "01", &rb_options); + rb_grn_scan_options(rb_options, + "recursive", &rb_recursive_p, + NULL); + if (NIL_P(rb_recursive_p)) { + rb_recursive_p = Qtrue; + } rb_grn_object_deconstruct(SELF(self), &object, &context, NULL, NULL, NULL, NULL); @@ -47,7 +61,11 @@ rb_grn_flushable_flush (VALUE self) rb_grn_context_check(context, self); + if (RVAL2CBOOL(rb_recursive_p)) { grn_obj_flush_recursive(context, object); + } else { + grn_obj_flush(context, object); + } return Qnil; } @@ -60,5 +78,5 @@ rb_grn_init_flushable (VALUE mGrn) rb_mGrnFlushable = rb_define_module_under(mGrn, "Flushable"); rb_define_method(rb_mGrnFlushable, "flush", - rb_grn_flushable_flush, 0); + rb_grn_flushable_flush, -1); } Modified: test/test-flushable.rb (+8 -0) =================================================================== --- test/test-flushable.rb 2015-07-10 18:15:05 +0900 (96cb029) +++ test/test-flushable.rb 2015-07-13 10:26:58 +0900 (237da2d) @@ -25,4 +25,12 @@ class FlushableTest < Test::Unit::TestCase table.flush end end + + def test_flush_not_recursive + table = Groonga::Hash.create + table.extend(Groonga::Flushable) + assert_nothing_raised do + table.flush(:recursive => false) + end + end end -------------- next part -------------- HTML����������������������������... ダウンロード