Kouhei Sutou
null+****@clear*****
Mon Feb 23 18:12:57 JST 2015
Kouhei Sutou 2015-02-23 18:12:57 +0900 (Mon, 23 Feb 2015) New Revision: dcdc3edb10b1f25a413040bbbd9d9b3d9a5a6383 https://github.com/groonga/groonga/commit/dcdc3edb10b1f25a413040bbbd9d9b3d9a5a6383 Message: mrb: add Object#domain_id, #range_id, #domain and #range Added files: lib/mrb/scripts/object.rb Modified files: lib/mrb/mrb_object.c lib/mrb/scripts/initialize/post.rb lib/mrb/scripts/sources.am Modified: lib/mrb/mrb_object.c (+38 -0) =================================================================== --- lib/mrb/mrb_object.c 2015-02-23 18:11:46 +0900 (b61c7b3) +++ lib/mrb/mrb_object.c 2015-02-23 18:12:57 +0900 (dc88b72) @@ -172,6 +172,39 @@ object_close(mrb_state *mrb, mrb_value self) } static mrb_value +object_get_domain_id(mrb_state *mrb, mrb_value self) +{ + grn_obj *object; + grn_id domain_id; + + object = DATA_PTR(self); + domain_id = object->header.domain; + + if (domain_id == GRN_ID_NIL) { + return mrb_nil_value(); + } else { + return mrb_fixnum_value(domain_id); + } +} + +static mrb_value +object_get_range_id(mrb_state *mrb, mrb_value self) +{ + grn_ctx *ctx = (grn_ctx *)mrb->ud; + grn_obj *object; + grn_id range_id; + + object = DATA_PTR(self); + range_id = grn_obj_get_range(ctx, object); + + if (range_id == GRN_ID_NIL) { + return mrb_nil_value(); + } else { + return mrb_fixnum_value(range_id); + } +} + +static mrb_value object_is_temporary(mrb_state *mrb, mrb_value self) { grn_obj *object; @@ -217,6 +250,11 @@ grn_mrb_object_init(grn_ctx *ctx) mrb_define_method(mrb, klass, "==", object_equal, MRB_ARGS_REQ(1)); mrb_define_method(mrb, klass, "close", object_close, MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "domain_id", object_get_domain_id, + MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "range_id", object_get_range_id, + MRB_ARGS_NONE()); + mrb_define_method(mrb, klass, "temporary?", object_is_temporary, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "persistent?", object_is_persistent, Modified: lib/mrb/scripts/initialize/post.rb (+1 -0) =================================================================== --- lib/mrb/scripts/initialize/post.rb 2015-02-23 18:11:46 +0900 (a295958) +++ lib/mrb/scripts/initialize/post.rb 2015-02-23 18:12:57 +0900 (ea26a03) @@ -4,6 +4,7 @@ require "context" require "writer" +require "object" require "database" require "index_column" require "command" Added: lib/mrb/scripts/object.rb (+11 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/object.rb 2015-02-23 18:12:57 +0900 (d98b506) @@ -0,0 +1,11 @@ +module Groonga + class Object + def domain + Context.instance[domain_id] + end + + def range + Context.instance[range_id] + end + end +end Modified: lib/mrb/scripts/sources.am (+1 -0) =================================================================== --- lib/mrb/scripts/sources.am 2015-02-23 18:11:46 +0900 (9b2ef95) +++ lib/mrb/scripts/sources.am 2015-02-23 18:12:57 +0900 (4dc7e0a) @@ -17,6 +17,7 @@ RUBY_SCRIPT_FILES = \ initialize/post.rb \ logger.rb \ logger/level.rb \ + object.rb \ operator.rb \ plugin_loader.rb \ require.rb \ -------------- next part -------------- HTML����������������������������... Download