[Groonga-commit] ranguba/rroonga at c3c6e9c [master] Add Groonga::Record#rename

アーカイブの一覧に戻る

Masafumi Yokoyama null+****@clear*****
Thu Oct 2 00:11:20 JST 2014


Masafumi Yokoyama	2014-10-02 00:11:20 +0900 (Thu, 02 Oct 2014)

  New Revision: c3c6e9c69e11bdd01f8f8f6e14dd9604de2ae04a
  https://github.com/ranguba/rroonga/commit/c3c6e9c69e11bdd01f8f8f6e14dd9604de2ae04a

  Message:
    Add Groonga::Record#rename
    
    [GitHub #22] Bind `grn_table_update_by_id()` and `grn_table_update()`

  Modified files:
    lib/groonga/record.rb
    test/test-record.rb

  Modified: lib/groonga/record.rb (+11 -0)
===================================================================
--- lib/groonga/record.rb    2014-09-30 18:31:26 +0900 (dfa768a)
+++ lib/groonga/record.rb    2014-10-02 00:11:20 +0900 (1af2012)
@@ -283,6 +283,17 @@ module Groonga
       @table.delete(@id)
     end
 
+    # キーを変更する。
+    #
+    # @since 4.0.5
+    def rename(new_key)
+      if****@table*****_a?(DoubleArrayTrie)
+        @table.update(@id, new_key, :id => true)
+      else
+        raise OperationNotSupported, "`#{@table.class}` does not support `Groonga::Record#rename`. Use `Groonga::DoubleArrayTrie`."
+      end
+    end
+
     # レコードが所属するテーブルをロックする。ロックに失敗した場
     # 合は {Groonga::ResourceDeadlockAvoided} 例外が発生する。
     #

  Modified: test/test-record.rb (+9 -0)
===================================================================
--- test/test-record.rb    2014-09-30 18:31:26 +0900 (b058186)
+++ test/test-record.rb    2014-10-02 00:11:20 +0900 (63e2adb)
@@ -176,6 +176,15 @@ class RecordTest < Test::Unit::TestCase
     assert_equal(2, @bookmarks.size)
   end
 
+  def test_rename
+    users = Groonga::DoubleArrayTrie.create(:name => "DATUsers",
+                                            :key_type => "ShortText")
+    bob = users.add("Bob")
+
+    bob.rename("Alice")
+    assert_equal("Alice", bob._key)
+  end
+
   def test_key
     documents = Groonga::PatriciaTrie.create(:name => "Documents",
                                              :key_type => "ShortText")
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る