[Groonga-commit] ranguba/rroonga at a3e1382 [master] Add Groonga::ID module

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jul 15 17:39:23 JST 2016


Kouhei Sutou	2016-07-15 17:39:23 +0900 (Fri, 15 Jul 2016)

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

  Message:
    Add Groonga::ID module
    
    New API:
    
      * Groonga::ID.builtin?
      * Groonga::ID::NIL
      * Groonga::ID::MAX

  Added files:
    ext/groonga/rb-grn-id.c
    test/test-id.rb
  Modified files:
    ext/groonga/rb-grn.h
    ext/groonga/rb-groonga.c

  Added: ext/groonga/rb-grn-id.c (+56 -0) 100644
===================================================================
--- /dev/null
+++ ext/groonga/rb-grn-id.c    2016-07-15 17:39:23 +0900 (ff40eff)
@@ -0,0 +1,56 @@
+/* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+  Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "rb-grn.h"
+
+/*
+ * Document-class: Groonga::ID
+ *
+ * This module provides Groonga ID related features.
+ */
+
+/*
+ * @overload builtin?(id)
+ *   @param [Integer] id The ID to be confirmed.
+ *   @return [Boolean] `true` if the `id` is builtin, `false` otherwise.
+ *
+ * @since 6.0.5
+ */
+static VALUE
+rb_grn_id_s_builtin_p (VALUE self, VALUE rb_id)
+{
+    grn_ctx *ctx = NULL;
+    grn_id id;
+
+    id = NUM2INT(rb_id);
+
+    return CBOOL2RVAL(grn_id_is_builtin(ctx, id));
+}
+
+void
+rb_grn_init_id (VALUE mGrn)
+{
+    VALUE mGrnID;
+
+    mGrnID = rb_define_module_under(mGrn, "ID");
+
+    rb_define_const(mGrnID, "NIL", INT2NUM(GRN_ID_NIL));
+    rb_define_const(mGrnID, "MAX", INT2NUM(GRN_ID_MAX));
+
+    rb_define_singleton_method(mGrnID, "builtin?", rb_grn_id_s_builtin_p, 1);
+}

  Modified: ext/groonga/rb-grn.h (+1 -0)
===================================================================
--- ext/groonga/rb-grn.h    2016-07-15 17:24:59 +0900 (473398f)
+++ ext/groonga/rb-grn.h    2016-07-15 17:39:23 +0900 (952c948)
@@ -365,6 +365,7 @@ void           rb_grn_init_index                    (VALUE mGrn);
 void           rb_grn_init_request_canceler         (VALUE mGrn);
 void           rb_grn_init_request_timer            (VALUE mGrn);
 void           rb_grn_init_request_timer_id         (VALUE mGrn);
+void           rb_grn_init_id                       (VALUE mGrn);
 
 VALUE          rb_grn_rc_to_exception               (grn_rc rc);
 const char    *rb_grn_rc_to_message                 (grn_rc rc);

  Modified: ext/groonga/rb-groonga.c (+1 -0)
===================================================================
--- ext/groonga/rb-groonga.c    2016-07-15 17:24:59 +0900 (d80495e)
+++ ext/groonga/rb-groonga.c    2016-07-15 17:39:23 +0900 (f71d0c3)
@@ -252,4 +252,5 @@ Init_groonga (void)
     rb_grn_init_request_canceler(mGrn);
     rb_grn_init_request_timer(mGrn);
     rb_grn_init_request_timer_id(mGrn);
+    rb_grn_init_id(mGrn);
 }

  Added: test/test-id.rb (+47 -0) 100644
===================================================================
--- /dev/null
+++ test/test-id.rb    2016-07-15 17:39:23 +0900 (e4fb401)
@@ -0,0 +1,47 @@
+# Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+class IDTest < Test::Unit::TestCase
+  include GroongaTestUtils
+
+  setup :setup_database
+
+  test "NIL" do
+    assert_equal(0, Groonga::ID::NIL)
+  end
+
+  test "MAX" do
+    assert_equal(2 ** 30 - 1, Groonga::ID::MAX)
+  end
+
+  sub_test_case(".builtin?") do
+    test "true" do
+      assert do
+        Groonga::ID.builtin?(Groonga::Type::INT32)
+      end
+    end
+
+    test "false" do
+      Groonga::Schema.define do |schema|
+        schema.create_table("Users", :type => :hash)
+      end
+      users_id = Groonga["Users"].id
+
+      assert do
+        not Groonga::ID.builtin?(users_id)
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
下载 



More information about the Groonga-commit mailing list
Back to archive index