ext/groonga/rb-grn-database.c in rroonga-2.0.4 vs ext/groonga/rb-grn-database.c in rroonga-2.0.5

- old
+ new

@@ -162,33 +162,28 @@ Data_Get_Struct(rb_context, RbGrnContext, rb_grn_context); rb_grn_context_reset_floating_objects(rb_grn_context); } /* - * call-seq: - * Groonga::Database.create(options=nil) -> Groonga::Database - * * 新しくデータベースを作成する。 + * _options_ にはハッシュでオプションを指定する。 + * @return [Groonga::Database] 作成されたデータベース + * @overload create(options=nil) + * @param option [::Hash] options The name and value + * pairs. Omitted names are initialized as the default value. + * @option options :path + * データベースを保存するパス。省略すると一時データベース + * となる。 + * @option options :context (Groonga::Context.default) + * データベースを結びつけるコンテキスト。省略すると + * Groonga::Context.defaultを利用する。 * - * _options_ にはハッシュでオプションを指定する。指定できるオ - * プションは以下の通り。 - * @param option [::Hash] options The name and value - * pairs. Omitted names are initialized as the default value. - * @option options :path The path - * - * データベースを保存するパス。省略すると一時データベース - * となる。 - * @option options :context (Groonga::Context.default) The context - * - * データベースを結びつけるコンテキスト。省略すると - * Groonga::Context.defaultを利用する。 - * * @example - * 一時データベースを作成: + * # 一時データベースを作成: * Groonga::Database.create * - * 永続データベースを作成: + * # 永続データベースを作成: * Groonga::Database.create(:path => "/tmp/db.groonga") */ static VALUE rb_grn_database_s_create (int argc, VALUE *argv, VALUE klass) { @@ -234,26 +229,28 @@ else return rb_database; } /* - * call-seq: - * Groonga::Database.new(path, options=nil) -> Groonga::Database - * Groonga::Database.new(path, options=nil) {|database| ...} - * * 既存のデータベースを開く。ブロックを指定した場合はブロッ * クに開いたデータベースを渡し、ブロックを抜けるときに閉じ * る。 - * - * _options_ にはハッシュでオプションを指定する。指定できるオ - * プションは以下の通り。 - * @param options [::Hash] The name and value - * pairs. Omitted names are initialized as the default value. - * @option options :context (Groonga::Context.default) The context - * - * データベースを結びつけるコンテキスト。省略すると - * Groonga::Context.defaultを利用する。 + * @overload new(path, options=nil) + * @param options [::Hash] The name and value + * pairs. Omitted names are initialized as the default value. + * @option options :context (Groonga::Context.default) + * データベースを結びつけるコンテキスト。省略すると + * Groonga::Context.defaultを利用する。 + * @return [Groonga::Database] + * @overload new(path, options=nil) + * @param options [::Hash] The name and value + * pairs. Omitted names are initialized as the default value. + * @option options :context (Groonga::Context.default) + * データベースを結びつけるコンテキスト。省略すると + * Groonga::Context.defaultを利用する。 + * @yield [database] + * @yieldparam [Groonga::Database] database 開いたデータベース */ static VALUE rb_grn_database_initialize (int argc, VALUE *argv, VALUE self) { grn_ctx *context; @@ -284,25 +281,26 @@ return Qnil; } /* - * call-seq: - * Groonga::Database.open(path, options=nil) -> Groonga::Database - * Groonga::Database.open(path, options=nil) {|database| ...} - * * 既存のデータベースを開く。ブロックを指定した場合はブロッ * クに開いたデータベースを渡し、ブロックを抜けるときに閉じ - * る。 - * - * _options_ にはハッシュでオプションを指定する。指定できるオ - * プションは以下の通り。 - * @param options [::Hash] The name and value - * pairs. Omitted names are initialized as the default value. - * @option options :context (Groonga::Context.default) The context - * - * データベースを結びつけるコンテキスト。 + * る。 _options_ にはハッシュでオプションを指定する。 + * @overload open(path, options=nil) + * @return [Groonga::Database] + * @param options [::Hash] The name and value + * pairs. Omitted names are initialized as the default value. + * @option options :context (Groonga::Context.default) The context + * データベースを結びつけるコンテキスト。 + * @overload open(path, options=nil) + * @param options [::Hash] The name and value + * pairs. Omitted names are initialized as the default value. + * @option options :context (Groonga::Context.default) The context + * データベースを結びつけるコンテキスト。 + * @yield [database] + * @yieldparam [Groonga::Database] database 開いたデータベース */ static VALUE rb_grn_database_s_open (int argc, VALUE *argv, VALUE klass) { VALUE database; @@ -314,16 +312,11 @@ else return database; } /* - * call-seq: - * database.each {|object| ...} - * database.each(options=nil) {|object| ...} - * * データベース内のオブジェクトを順番にブロックに渡す。 - * * @example すべてのオブジェクトの名前を表示する: * database.each do |object| * p object.name * end * @@ -335,43 +328,56 @@ * @example すべてのオブジェクトの名前をキー名の降順で表示する: * database.each(:order_by => :key, :order => :desc) do |object| * p object.name * end * - * @param options [::Hash] - * @option options :order The order - * +:asc+ または +:ascending+ を指定すると昇順にレコードを取 - * り出す。(デフォルト) + * @overload each(options=nil) + * @macro [new] database.each.options + * @param options [::Hash] + * @yield [object] + * @option options :order + * +:asc+ または +:ascending+ を指定すると昇順にレコードを取 + * り出す。(デフォルト) + * +:desc+ または +:descending+ を指定すると降順にレコードを + * 取り出す。 + * @option options :order_by (:key) + * +:id+ を指定するとID順にレコードを取り出す。 + * +:key+ 指定するとキー順にレコードを取り出す。(デフォル + * ト) + * @macro database.each.options * - * +:desc+ または +:descending+ を指定すると降順にレコードを - * 取り出す。 + * @overload each(options=nil) + * @macro database.each.options + * @option options :ignore_missing_object (false) + * Specify +true+ to ignore missing object. Otherwise, an exception is + * raised for missing object. * - * @option options :order_by (:key) The ordef by - * +:id+ を指定するとID順にレコードを取り出す。 - * - * +:key+ 指定するとキー順にレコードを取り出す。(デフォル - * ト) - * + * @since 2.0.5 */ static VALUE rb_grn_database_each (int argc, VALUE *argv, VALUE self) { grn_ctx *context = NULL; grn_obj *database; grn_table_cursor *cursor; VALUE rb_cursor, rb_options, rb_order, rb_order_by; + VALUE rb_ignore_missing_object; int flags = 0; grn_id id; + VALUE exception; + RETURN_ENUMERATOR(self, argc, argv); + rb_grn_database_deconstruct(SELF(self), &database, &context, NULL, NULL, NULL, NULL); rb_scan_args(argc, argv, "01", &rb_options); rb_grn_scan_options(rb_options, "order", &rb_order, "order_by", &rb_order_by, + "ignore_missing_object", &rb_ignore_missing_object, NULL); flags |= rb_grn_table_cursor_order_to_flag(rb_order); flags |= rb_grn_table_cursor_order_by_to_flag(GRN_TABLE_PAT_KEY, self, @@ -384,12 +390,25 @@ rb_iv_set(self, "cursor", rb_cursor); while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) { grn_obj *object; object = grn_ctx_at(context, id); - if (object) + if (!object && RTEST(rb_ignore_missing_object)) { + context->rc = GRN_SUCCESS; + continue; + } + + exception = rb_grn_context_to_exception(context, self); + if (!NIL_P(exception)) { + rb_grn_object_close(rb_cursor); + rb_iv_set(self, "cursor", Qnil); + rb_exc_raise(exception); + } + + if (object) { rb_yield(GRNOBJECT2RVAL(Qnil, context, object, GRN_FALSE)); + } } rb_grn_object_close(rb_cursor); rb_iv_set(self, "cursor", Qnil); return Qnil; @@ -419,29 +438,26 @@ return Qnil; } /* - * Document-method: lock - * - * call-seq: - * database.lock(options={}) - * database.lock(options={}) {...} - * * _database_ をロックする。ロックに失敗した場合は * Groonga::ResourceDeadlockAvoided例外が発生する。 * - * ブロックを指定した場合はブロックを抜けたときにunlockする。 - * - * 利用可能なオプションは以下の通り。 - * @param [::Hash] options The name and value - * pairs. Omitted names are initialized as the default value - * @option options :timeout The timeout - * - * ロックを獲得できなかった場合は _:timeout_ 秒間ロックの獲 - * 得を試みる。 _:timeout_ 秒以内にロックを獲得できなかった - * 場合は例外が発生する。 + * @overload lock(options={}) + * @param [::Hash] options 利用可能なオプションは以下の通り。 + * @option options :timeout + * ロックを獲得できなかった場合は _:timeout_ 秒間ロックの獲 + * 得を試みる。 _:timeout_ 秒以内にロックを獲得できなかった + * 場合は例外が発生する。 + * @overload lock(options={}) + * @yield ブロックを指定した場合はブロックを抜けたときにunlockする。 + * @param [::Hash] options 利用可能なオプションは以下の通り。 + * @option options :timeout + * ロックを獲得できなかった場合は _:timeout_秒間ロックの獲 + * 得を試みる。 _:timeout_秒以内にロックを獲得できなかった + * 場合は例外が発生する。 */ static VALUE rb_grn_database_lock (int argc, VALUE *argv, VALUE self) { grn_ctx *context; @@ -535,21 +551,17 @@ grn_db_touch(context, database); return Qnil; } /* - * Document-method: defrag - * - * call-seq: - * database.defrag(options={}) -> n_segments - * * Defrags all variable size columns in the database. - * * @return [Integer] the number of defraged segments - * @option options [Integer] :threshold (0) the threshold to - * determine whether a segment is defraged. Available - * values are -4..22. -4 means all segments are defraged. - * 22 means no segment is defraged. + * @overload defrag(options={}) + * @param [::Hash] options option for defrag + * @option options [Integer] :threshold (0) the threshold to + * determine whether a segment is defraged. Available + * values are -4..22. -4 means all segments are defraged. + * 22 means no segment is defraged. * @since 1.2.6 */ static VALUE rb_grn_database_defrag (int argc, VALUE *argv, VALUE self) {