Masafumi Yokoyama
null+****@clear*****
Thu Oct 2 23:35:44 JST 2014
Masafumi Yokoyama 2014-10-02 23:35:44 +0900 (Thu, 02 Oct 2014) New Revision: 06e06f7ef5b754ee65f34169108e4631f1dad300 https://github.com/ranguba/rroonga/commit/06e06f7ef5b754ee65f34169108e4631f1dad300 Message: Add `:id => true` option to Groonga::Table::KeySupport#delete GitHub #23: `Groonga::Table::KeySupport#delete` accepts both ID and key. If passed value is integer, it is handled as ID. But we can use `Int32` as key. In the case, we can't delete a record by key. Add `Groonga::Table::KeySupport#delete(id, :id => true)` API. It introduces a backward incompatibility. But it is OK because the current API is a bug. Modified files: ext/groonga/rb-grn-table-key-support.c test/test-hash.rb Modified: ext/groonga/rb-grn-table-key-support.c (+9 -4) =================================================================== --- ext/groonga/rb-grn-table-key-support.c 2014-10-02 22:38:58 +0900 (cb0e2c5) +++ ext/groonga/rb-grn-table-key-support.c 2014-10-02 23:35:44 +0900 (09cc370) @@ -1,5 +1,6 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* + Copyright (C) 2014 Masafumi Yokoyama <myokoym �� gmail.com> Copyright (C) 2009-2013 Kouhei Sutou <kou �� clear-code.com> This library is free software; you can redistribute it and/or @@ -378,7 +379,7 @@ rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key) } /* - * @overload delete(id) + * @overload delete(id, :id=>true) * Delete a record that has ID @id �� . * * @param id [Integer] The ID of delete target record. @@ -405,14 +406,18 @@ rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key) static VALUE rb_grn_table_key_support_delete (int argc, VALUE *argv, VALUE self) { - VALUE rb_id_or_key; + VALUE rb_id_or_key, rb_options; + VALUE rb_option_id; if (rb_block_given_p()) { return rb_grn_table_delete_by_expression(self); } - rb_scan_args(argc, argv, "1", &rb_id_or_key); - if (FIXNUM_P(rb_id_or_key)) { + rb_scan_args(argc, argv, "11", &rb_id_or_key, &rb_options); + rb_grn_scan_options(rb_options, + "id", &rb_option_id, + NULL); + if (RVAL2CBOOL(rb_option_id)) { return rb_grn_table_delete_by_id(self, rb_id_or_key); } else { return rb_grn_table_key_support_delete_by_key(self, rb_id_or_key); Modified: test/test-hash.rb (+13 -1) =================================================================== --- test/test-hash.rb 2014-10-02 22:38:58 +0900 (30ad504) +++ test/test-hash.rb 2014-10-02 23:35:44 +0900 (9b8fccb) @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # +# Copyright (C) 2014 Masafumi Yokoyama <myokoym �� gmail.com> # Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or @@ -55,7 +56,7 @@ class HashTest < Test::Unit::TestCase end def test_id - @bookmarks.delete(@google.id) + @bookmarks.delete(@google.id, :id => true) assert_equal(["groonga", "Cutter"], @bookmarks.collect {|bookmark| bookmark.key}) end @@ -73,6 +74,17 @@ class HashTest < Test::Unit::TestCase assert_equal(["Google", "Cutter"], @bookmarks.collect {|bookmark| bookmark.key}) end + + def test_key_of_int32 + numbers = Groonga::Hash.create(:name => "Numbers", + :key_type => "Int32") + numbers.add(100) + numbers.add(200) + + numbers.delete(100) + assert_equal([200], + numbers.collect {|number| number.key}) + end end def test_value -------------- next part -------------- HTML����������������������������... Descargar