Navigation Menu

Skip to content

Commit

Permalink
Support grn_proc_get_type()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 8, 2014
1 parent 6308f5b commit 0112ea0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
40 changes: 40 additions & 0 deletions ext/groonga/rb-grn-procedure-type.c
@@ -0,0 +1,40 @@
/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "rb-grn.h"

void
rb_grn_init_procedure_type (VALUE mGrn)
{
VALUE rb_mGrnProcedureType;

rb_mGrnProcedureType = rb_define_module_under(mGrn, "ProcedureType");

rb_define_const(rb_mGrnProcedureType,
"INVALID", INT2NUM(GRN_PROC_INVALID));
rb_define_const(rb_mGrnProcedureType,
"TOKENIZER", INT2NUM(GRN_PROC_TOKENIZER));
rb_define_const(rb_mGrnProcedureType,
"COMMAND", INT2NUM(GRN_PROC_COMMAND));
rb_define_const(rb_mGrnProcedureType,
"FUNCTION", INT2NUM(GRN_PROC_FUNCTION));
rb_define_const(rb_mGrnProcedureType,
"HOOK", INT2NUM(GRN_PROC_HOOK));
rb_define_const(rb_mGrnProcedureType,
"NORMALIZER", INT2NUM(GRN_PROC_NORMALIZER));
}
19 changes: 16 additions & 3 deletions ext/groonga/rb-grn-procedure.c
@@ -1,6 +1,6 @@
/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
Copyright (C) 2009-2014 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
Expand All @@ -18,8 +18,6 @@

#include "rb-grn.h"

#define SELF(object) (RVAL2GRNPROCEDURE(object))

VALUE rb_cGrnProcedure;

grn_obj *
Expand All @@ -39,6 +37,19 @@ rb_grn_procedure_to_ruby_object (grn_ctx *context, grn_obj *procedure,
return GRNOBJECT2RVAL(rb_cGrnProcedure, context, procedure, owner);
}

static VALUE
rb_grn_procedure_get_type (VALUE self)
{
grn_ctx *context;
grn_obj *procedure;
grn_proc_type type;

procedure = RVAL2GRNOBJECT(self, &context);
type = grn_proc_get_type(context, procedure);

return INT2NUM(type);
}

void
rb_grn_init_procedure (VALUE mGrn)
{
Expand All @@ -49,4 +60,6 @@ rb_grn_init_procedure (VALUE mGrn)
rb_define_const(rb_cGrnProcedure, "BIGRAM", INT2NUM(GRN_DB_BIGRAM));
rb_define_const(rb_cGrnProcedure, "TRIGRAM", INT2NUM(GRN_DB_TRIGRAM));
rb_define_const(rb_cGrnProcedure, "MECAB", INT2NUM(GRN_DB_MECAB));

rb_define_method(rb_cGrnProcedure, "type", rb_grn_procedure_get_type, 0);
}
1 change: 1 addition & 0 deletions ext/groonga/rb-grn.h
Expand Up @@ -288,6 +288,7 @@ void rb_grn_init_patricia_trie_cursor (VALUE mGrn);
void rb_grn_init_double_array_trie_cursor (VALUE mGrn);
void rb_grn_init_type (VALUE mGrn);
void rb_grn_init_procedure (VALUE mGrn);
void rb_grn_init_procedure_type (VALUE mGrn);
void rb_grn_init_column (VALUE mGrn);
void rb_grn_init_fix_size_column (VALUE mGrn);
void rb_grn_init_variable_size_column (VALUE mGrn);
Expand Down
3 changes: 2 additions & 1 deletion ext/groonga/rb-groonga.c
@@ -1,6 +1,6 @@
/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2009-2013 Kouhei Sutou <kou@clear-code.com>
Copyright (C) 2009-2014 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
Expand Down Expand Up @@ -175,6 +175,7 @@ Init_groonga (void)
rb_grn_init_posting(mGrn);
rb_grn_init_type(mGrn);
rb_grn_init_procedure(mGrn);
rb_grn_init_procedure_type(mGrn);
rb_grn_init_column(mGrn);
rb_grn_init_accessor(mGrn);
rb_grn_init_geo_point(mGrn);
Expand Down
9 changes: 8 additions & 1 deletion test/test-procedure.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2009-2014 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
Expand Down Expand Up @@ -34,4 +34,11 @@ def assert_equal_procedure(expected_name, id, options={})
assert_equal(expected_name,
procedure ? procedure.name : procedure)
end

class TypeTest < self
def test_tokenizer
tokenizer = Groonga["TokenBigram"]
assert_equal(Groonga::ProcedureType::TOKENIZER, tokenizer.type)
end
end
end

0 comments on commit 0112ea0

Please sign in to comment.