Class: Couchbase::Collection::ScanResults

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/couchbase/collection_options.rb,
/code/couchbase-ruby-client/lib/couchbase/collection_options.rb

Instance Method Summary collapse

Constructor Details

#initialize(core_scan_result:, transcoder:) ⇒ ScanResults

Returns a new instance of ScanResults.



367
368
369
370
# File 'lib/couchbase/collection_options.rb', line 367

def initialize(core_scan_result:, transcoder:)
  @core_scan_result = core_scan_result
  @transcoder = transcoder
end

Instance Method Details

#eachObject



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/couchbase/collection_options.rb', line 372

def each
  return enum_for(:each) unless block_given?

  loop do
    resp = @core_scan_result.next_item

    break if resp.nil?

    if resp[:id_only]
      yield ScanResult.new(
        id: resp[:id],
        id_only: resp[:id_only],
        transcoder: @transcoder
      )
    else
      yield ScanResult.new(
        id: resp[:id],
        id_only: resp[:id_only],
        cas: resp[:cas],
        expiry: resp[:expiry],
        encoded: resp[:encoded],
        flags: resp[:flags],
        transcoder: @transcoder
      )
    end
  end
end