| 1 |
module Groonga |
| 2 |
class Database |
| 3 |
def each_raw(options=nil) |
| 4 |
return to_enum(__method__, options) unless block_given? |
| 5 |
|
| 6 |
if options |
| 7 |
min = options[:prefix] |
| 8 |
order = options[:order] |
| 9 |
order_by = options[:order_by] |
| 10 |
else |
| 11 |
min = nil |
| 12 |
order = :ascending |
| 13 |
order_by = :id |
| 14 |
end |
| 15 |
flags = 0 |
| 16 |
|
| 17 |
if order == :descending |
| 18 |
flags |= TableCursorFlags::DESCENDING |
| 19 |
else |
| 20 |
flags |= TableCursorFlags::ASCENDING |
| 21 |
end |
| 22 |
if order_by == :id |
| 23 |
flags |= TableCursorFlags::BY_ID |
| 24 |
else |
| 25 |
flags |= TableCursorFlags::BY_KEY |
| 26 |
end |
| 27 |
flags |= TableCursorFlags::PREFIX if min |
| 28 |
TableCursor.open(self, :min => min, :flags => flags) do |cursor| |
| 29 |
cursor.each do |id| |
| 30 |
yield(id, cursor) |
| 31 |
end |
| 32 |
end |
| 33 |
end |
| 34 |
|
| 35 |
def each(options=nil) |
| 36 |
return to_enum(__method__, options) unless block_given? |
| 37 |
|
| 38 |
context = Context.instance |
| 39 |
each_raw(options) do |id, cursor| |
| 40 |
object = context[id] |
| 41 |
yield(object) if object |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
def each_name(options=nil) |
| 46 |
return to_enum(__method__, options) unless block_given? |
| 47 |
|
| 48 |
each_raw(options) do |id, cursor| |
| 49 |
name = cursor.key |
| 50 |
yield(name) |
| 51 |
end |
| 52 |
end |
| 53 |
|
| 54 |
def each_table(options={}) |
| 55 |
return to_enum(__method__, options) unless block_given? |
| 56 |
|
| 57 |
context = Context.instance |
| 58 |
each_name(options) do |name| |
| 59 |
next if name.include?(".") |
| 60 |
object = context[name] |
| 61 |
yield(object) if object.is_a?(Table) |
| 62 |
end |
| 63 |
end |
| 64 |
end |
| 65 |
end |