summaryrefslogtreecommitdiff
path: root/storage/mroonga/vendor/groonga/lib/mrb/scripts/table_cursor.rb
blob: 45949b717c86ce0eaa6bb91bffb58cbdb9a84637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Groonga
  class TableCursor
    include Enumerable

    class << self
      def open(*arguments)
        cursor = open_raw(*arguments)
        if block_given?
          begin
            yield(cursor)
          ensure
            cursor.close
          end
        else
          cursor
        end
      end
    end

    def each
      loop do
        id = self.next
        return if id == Groonga::ID::NIL
        yield(id)
      end
    end
  end
end