Class: VinaryTree::Libdictenstein::EntryStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vinary_tree/libdictenstein.rb

Overview

Public bounded stream. Enumerable#each uses ensure so break and raised exceptions deterministically close the native cursor.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle, max_entries:, max_units:, max_values:) ⇒ EntryStream

Returns a new instance of EntryStream.



245
246
247
248
249
250
251
252
253
254
# File 'lib/vinary_tree/libdictenstein.rb', line 245

def initialize(handle, max_entries:, max_units:, max_values:)
  @state = EntryCursorState.new(
    handle,
    max_entries: max_entries,
    max_units: max_units,
    max_values: max_values
  )
  @info = @state.info
  ObjectSpace.define_finalizer(self, self.class.finalizer(@state))
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



243
244
245
# File 'lib/vinary_tree/libdictenstein.rb', line 243

def info
  @info
end

Class Method Details

.finalizer(state) ⇒ Object



256
# File 'lib/vinary_tree/libdictenstein.rb', line 256

def self.finalizer(state) = proc { state.close rescue nil }

Instance Method Details

#cancelObject



272
# File 'lib/vinary_tree/libdictenstein.rb', line 272

def cancel = @state.cancel

#closeObject



274
275
276
277
278
# File 'lib/vinary_tree/libdictenstein.rb', line 274

def close
  @state.close
  ObjectSpace.undefine_finalizer(self) if @state.closed?
  nil
end

#eachObject



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/vinary_tree/libdictenstein.rb', line 260

def each
  return enum_for(__method__) unless block_given?
  begin
    while (entry = self.next)
      yield entry
    end
  ensure
    close
  end
  self
end

#nextObject



258
# File 'lib/vinary_tree/libdictenstein.rb', line 258

def next = @state.next_entry