[Groonga-commit] ranguba/rroonga at a20ddfd [master] Add column predicates

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jul 15 18:15:09 JST 2016


Kouhei Sutou	2016-07-15 18:15:09 +0900 (Fri, 15 Jul 2016)

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

  Message:
    Add column predicates
    
      * Groonga::Object#column?
      * Groonga::Object#reference_column?
      * Groonga::Object#index_column?

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

  Modified: ext/groonga/rb-grn-object.c (+82 -0)
===================================================================
--- ext/groonga/rb-grn-object.c    2016-07-15 18:08:52 +0900 (5daba09)
+++ ext/groonga/rb-grn-object.c    2016-07-15 18:15:09 +0900 (42ac6ea)
@@ -1550,6 +1550,83 @@ rb_grn_object_table_p (VALUE self)
 }
 
 /*
+ * Checks whether the object is column or not.
+ *
+ * @overload column?
+ *   @return [Boolean] `true` if the object is column, `false` otherwise.
+ *
+ * @since 6.0.5
+ */
+static VALUE
+rb_grn_object_column_p (VALUE self)
+{
+    grn_ctx *context;
+    grn_obj *object;
+    grn_bool column_p = GRN_FALSE;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+
+    if (context && object) {
+        column_p = grn_obj_is_column(context, object);
+    }
+
+    return CBOOL2RVAL(column_p);
+}
+
+/*
+ * Checks whether the object is reference column or not.
+ *
+ * @overload reference_column?
+ *   @return [Boolean] `true` if the object is reference column,
+ *     `false` otherwise.
+ *
+ * @since 6.0.5
+ */
+static VALUE
+rb_grn_object_reference_column_p (VALUE self)
+{
+    grn_ctx *context;
+    grn_obj *object;
+    grn_bool reference_column_p = GRN_FALSE;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+
+    if (context && object) {
+        reference_column_p = grn_obj_is_reference_column(context, object);
+    }
+
+    return CBOOL2RVAL(reference_column_p);
+}
+
+/*
+ * Checks whether the object is index column or not.
+ *
+ * @overload index_column?
+ *   @return [Boolean] `true` if the object is index column,
+ *     `false` otherwise.
+ *
+ * @since 6.0.5
+ */
+static VALUE
+rb_grn_object_index_column_p (VALUE self)
+{
+    grn_ctx *context;
+    grn_obj *object;
+    grn_bool index_column_p = GRN_FALSE;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+
+    if (context && object) {
+        index_column_p = grn_obj_is_index_column(context, object);
+    }
+
+    return CBOOL2RVAL(index_column_p);
+}
+
+/*
  * Checks whether the object is procedure or not.
  *
  * @overload procedure?
@@ -1803,6 +1880,11 @@ rb_grn_init_object (VALUE mGrn)
 
     rb_define_method(rb_cGrnObject, "builtin?", rb_grn_object_builtin_p, 0);
     rb_define_method(rb_cGrnObject, "table?", rb_grn_object_table_p, 0);
+    rb_define_method(rb_cGrnObject, "column?", rb_grn_object_column_p, 0);
+    rb_define_method(rb_cGrnObject, "reference_column?",
+                     rb_grn_object_reference_column_p, 0);
+    rb_define_method(rb_cGrnObject, "index_column?",
+                     rb_grn_object_index_column_p, 0);
     rb_define_method(rb_cGrnObject, "procedure?", rb_grn_object_procedure_p, 0);
     rb_define_method(rb_cGrnObject, "function_procedure?",
                      rb_grn_object_function_procedure_p, 0);

  Modified: test/test-column.rb (+34 -0)
===================================================================
--- test/test-column.rb    2016-07-15 18:08:52 +0900 (2124afd)
+++ test/test-column.rb    2016-07-15 18:15:09 +0900 (82542c1)
@@ -349,6 +349,40 @@ class ColumnTest < Test::Unit::TestCase
     end
   end
 
+  def test_column?
+    assert do
+      @users_name_column.column?
+    end
+  end
+
+  sub_test_case "#reference_column" do
+    test "true" do
+      assert do
+        @bookmarks_user.reference_column?
+      end
+    end
+
+    test "false" do
+      assert do
+        not @users_name_column.reference_column?
+      end
+    end
+  end
+
+  sub_test_case "#index_column?" do
+    test "true" do
+      assert do
+        @bookmarks_index_content.index_column?
+      end
+    end
+
+    test "false" do
+      assert do
+        not @users_name_column.index_column?
+      end
+    end
+  end
+
   private
   def assert_content_search(expected_records, term)
     records = @bookmarks_index_content.search(term).records
-------------- next part --------------
HTML����������������������������...
Download 



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