Class: Rufus::Tokyo::TableResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rufus/tokyo/cabinet/table.rb

Overview

The thing queries return

Instance Method Summary collapse

Constructor Details

#initialize(table, list_pointer, query_opts) ⇒ TableResultSet

Returns a new instance of TableResultSet



862
863
864
865
866
867
# File 'lib/rufus/tokyo/cabinet/table.rb', line 862

def initialize (table, list_pointer, query_opts)

  @table = table
  @list = Rufus::Tokyo::List.new(list_pointer)
  @opts = query_opts
end

Instance Method Details

#eachObject

The classical each



880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'lib/rufus/tokyo/cabinet/table.rb', line 880

def each

  (0..size-1).each do |i|
    pk = @list[i]
    if @opts[:pk_only]
      yield(pk)
    else
      val = @table[pk]
      val[:pk] = pk unless @opts[:no_pk]
      yield(val)
    end
  end
end

#freeObject Also known as: close, destroy

Frees this query (the underlying Tokyo Cabinet list structure)



903
904
905
906
907
# File 'lib/rufus/tokyo/cabinet/table.rb', line 903

def free

  @list.free
  @list = nil
end

#sizeObject Also known as: length

Returns the count of element in this result set



871
872
873
874
# File 'lib/rufus/tokyo/cabinet/table.rb', line 871

def size

  @list.size
end

#to_aObject

Returns an array of hashes



896
897
898
899
# File 'lib/rufus/tokyo/cabinet/table.rb', line 896

def to_a

  collect { |m| m }
end