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.



170
171
172
173
174
175
176
177
# File 'lib/level_db.rb', line 170

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

Instance Method Details

#closeObject



179
180
181
# File 'lib/level_db.rb', line 179

def close
  @iterator.close
end

#eachObject



194
195
196
197
198
199
200
# File 'lib/level_db.rb', line 194

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

#nextObject

Raises:

  • (StopIteration)


183
184
185
186
187
# File 'lib/level_db.rb', line 183

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

#next?Boolean

Returns:

  • (Boolean)


189
190
191
192
# File 'lib/level_db.rb', line 189

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

#rewindObject



202
203
204
205
206
207
# File 'lib/level_db.rb', line 202

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