[Groonga-commit] ranguba/rroonga at 468f384 [master] Bind grn_obj_is_accessor()

Back to archive index

Masafumi Yokoyama null+****@clear*****
Tue Jan 5 12:32:57 JST 2016


Masafumi Yokoyama	2016-01-05 12:32:57 +0900 (Tue, 05 Jan 2016)

  New Revision: 468f38467b42aff28bfd74992f713db7290161d6
  https://github.com/ranguba/rroonga/commit/468f38467b42aff28bfd74992f713db7290161d6

  Merged 930b611: Merge pull request #111 from ranguba/bind-grn_obj_is_accessor

  Message:
    Bind grn_obj_is_accessor()
    
    GitHub: #110

  Modified files:
    ext/groonga/rb-grn-object.c
    test/test-accessor.rb

  Modified: ext/groonga/rb-grn-object.c (+29 -1)
===================================================================
--- ext/groonga/rb-grn-object.c    2016-01-05 14:06:57 +0900 (a87f84e)
+++ ext/groonga/rb-grn-object.c    2016-01-05 12:32:57 +0900 (2a93260)
@@ -1,7 +1,7 @@
 /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
   Copyright (C) 2009-2014  Kouhei Sutou <kou �� clear-code.com>
-  Copyright (C) 2014-2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
+  Copyright (C) 2014-2016  Masafumi Yokoyama <yokoyama �� 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
@@ -1656,6 +1656,32 @@ rb_grn_object_scorer_procedure_p (VALUE self)
     return CBOOL2RVAL(scorer_procedure_p);
 }
 
+/*
+ * Checks whether the object is accessor or not.
+ *
+ * @overload accessor?
+ *   @return [Boolean] `true` if the object is accessor,
+ *     `false` otherwise.
+ *
+ * @since 5.1.1
+ */
+static VALUE
+rb_grn_object_accessor_p (VALUE self)
+{
+    grn_ctx *context;
+    grn_obj *object;
+    grn_bool accessor_p = GRN_FALSE;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+
+    if (context && object) {
+        accessor_p = grn_obj_is_accessor(context, object);
+    }
+
+    return CBOOL2RVAL(accessor_p);
+}
+
 void
 rb_grn_init_object (VALUE mGrn)
 {
@@ -1701,4 +1727,6 @@ rb_grn_init_object (VALUE mGrn)
                      rb_grn_object_selector_only_procedure_p, 0);
     rb_define_method(rb_cGrnObject, "scorer_procedure?",
                      rb_grn_object_scorer_procedure_p, 0);
+    rb_define_method(rb_cGrnObject, "accessor?",
+                     rb_grn_object_accessor_p, 0);
 }

  Modified: test/test-accessor.rb (+15 -0)
===================================================================
--- test/test-accessor.rb    2016-01-05 14:06:57 +0900 (572405d)
+++ test/test-accessor.rb    2016-01-05 12:32:57 +0900 (ff851a4)
@@ -1,4 +1,5 @@
 # Copyright (C) 2011  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2016  Masafumi Yokoyama <yokoyama �� 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
@@ -33,4 +34,18 @@ class AccessorTest < Test::Unit::TestCase
   def test_local_name
     assert_equal("_id", @id.local_name)
   end
+
+  sub_test_case "#accessor?" do
+    test "true" do
+      assert do
+        @id.accessor?
+      end
+    end
+
+    test "false" do
+      assert do
+        not****@posts*****?
+      end
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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