Class: Oinky::ColumnSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/oinky.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, colnames) ⇒ ColumnSelector

Returns a new instance of ColumnSelector.



684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/oinky.rb', line 684

def initialize(table, colnames)
  th = table.send(:eval, "@handle")

  # Make an array of strings.
  colnames = [colnames] unless colnames.is_a? Enumerable
  colnames = colnames.to_a
  colnames = colnames.map {|v| v.to_s}

  # Make an array of c-strings
  cols = FFI::MemoryPointer.new(:string, colnames.size)
  native = NativeMallocBuffer.new((colnames * "\x00") + "\x00")
  ptr = native.ptr
  colnames.each_with_index{|s,i|
    # The routine expects null-terminated strings.
    cols[i].write_pointer(ptr)
    ptr = ptr + s.length + 1
  }

  cs = FFI::MemoryPointer.new :pointer
  Internal.wrap_oinky(Internal.oinky_table_make_column_selector(th, colnames.size, cols, cs))
  @handle, @cols = [cs.read_pointer, colnames]

  ObjectSpace.define_finalizer( self, self.class.finalize(table, @handle) )
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



719
720
721
# File 'lib/oinky.rb', line 719

def cols
  @cols
end

#handleObject (readonly)

Returns the value of attribute handle.



719
720
721
# File 'lib/oinky.rb', line 719

def handle
  @handle
end

Class Method Details

.finalize(tptr, hptr) ⇒ Object



709
710
711
# File 'lib/oinky.rb', line 709

def self.finalize(tptr, hptr)
  proc { Internal.oinky_table_delete_column_selector(tptr, hptr) }
end

Instance Method Details

#cloneObject

column selectors are immutable. cloning would cause us to free twice anyway.



715
716
717
# File 'lib/oinky.rb', line 715

def clone
  self
end

#sizeObject



721
722
723
# File 'lib/oinky.rb', line 721

def size
  cols.size
end