Class: LevelDb::Cursor

Inherits:
Object
  • Object
show all
Includes:
Encoding, LazyEnumerable
Defined in:
lib/level_db.rb

Instance Method Summary collapse

Methods included from LazyEnumerable

#map, #select

Methods included from Encoding

#decode_key, #decode_value, #encode_key, #encode_value

Constructor Details

#initialize(iterator, options = {}) ⇒ Cursor

Returns a new instance of Cursor.



206
207
208
209
210
211
212
213
# File 'lib/level_db.rb', line 206

def initialize(iterator, options={})
  @iterator = iterator
  @from = options[:from]
  @to = options[:to]
  @reverse = options[:reverse]
  @limit = options[:limit]
  rewind
end

Instance Method Details

#closeObject



215
216
217
# File 'lib/level_db.rb', line 215

def close
  @iterator.close
end

#eachObject



230
231
232
233
234
235
236
# File 'lib/level_db.rb', line 230

def each
  return self unless block_given?
  rewind
  yield self.next while next?
  close
  self
end

#nextObject

Raises:

  • (StopIteration)


219
220
221
222
223
# File 'lib/level_db.rb', line 219

def next
  raise StopIteration unless next?
  v, @next = @next, nil
  v
end

#next?Boolean

Returns:

  • (Boolean)


225
226
227
228
# File 'lib/level_db.rb', line 225

def next?
  @next = internal_next unless @next
  !!@next
end

#rewindObject



238
239
240
241
242
243
# File 'lib/level_db.rb', line 238

def rewind
  @next = nil
  @started = false
  @exhausted = false
  @count = 0
end