Navigation Menu

Skip to content

Commit

Permalink
Add Column#data?
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 25, 2017
1 parent 8f3e896 commit f3730d3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/groonga/rb-grn-column.c
Expand Up @@ -706,6 +706,26 @@ rb_grn_column_scalar_p (VALUE self)
}
}

/*
* @overload data?
* @return [Bool] `true` if the column is a data column (a scalar
* column or a vector column), `false` otherwise.
*
* @since 7.0.2
*/
static VALUE
rb_grn_column_data_p (VALUE self)
{
grn_ctx *context;
grn_obj *column;

rb_grn_column_deconstruct(SELF(self), &column, &context,
NULL, NULL,
NULL, NULL, NULL);

return CBOOL2RVAL(grn_obj_is_data_column(context, column));
}

/*
* @overload with_weight?
* @return [Boolean] @true@ if the column is vector and created with
Expand Down Expand Up @@ -857,6 +877,7 @@ rb_grn_init_column (VALUE mGrn)
rb_define_method(rb_cGrnColumn, "weight_vector?",
rb_grn_column_weight_vector_p, 0);
rb_define_method(rb_cGrnColumn, "scalar?", rb_grn_column_scalar_p, 0);
rb_define_method(rb_cGrnColumn, "data?", rb_grn_column_data_p, 0);

rb_define_method(rb_cGrnColumn, "with_weight?",
rb_grn_column_with_weight_p, 0);
Expand Down
6 changes: 6 additions & 0 deletions test/test-fix-size-column.rb
Expand Up @@ -138,6 +138,12 @@ def test_scalar?
assert_predicate(@n_viewed, :scalar?)
end

def test_data?
assert do
@n_viewed.data?
end
end

def test_inspect
assert_equal("#<Groonga::FixSizeColumn " +
"id: <#{@n_viewed.id}>, " +
Expand Down
6 changes: 6 additions & 0 deletions test/test-index-column.rb
Expand Up @@ -57,6 +57,12 @@ def test_weight_vector?
def test_scalar?
assert_not_predicate(@index, :scalar?)
end

def test_data?
assert do
not @index.data?
end
end
end

class CRUDTest < self
Expand Down
6 changes: 6 additions & 0 deletions test/test-variable-size-column.rb
Expand Up @@ -79,6 +79,12 @@ def test_scalar?
assert_not_predicate(@nick_names, :scalar?)
end

def test_data?
assert do
@nick_names.data?
end
end

def test_compressed?
description = @users.define_column("description", "ShortText",
:compress => :zlib)
Expand Down

0 comments on commit f3730d3

Please sign in to comment.