Class: Oinky::Internal::IndexColumnDefn

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

Defined Under Namespace

Classes: IxColumnSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#refsObject

Returns the value of attribute refs.



379
380
381
# File 'lib/oinky.rb', line 379

def refs
  @refs
end

Class Method Details

.make(name, ascending = true) ⇒ Object



386
387
388
389
390
# File 'lib/oinky.rb', line 386

def self.make(name, ascending = true)
  v = IndexColumnDefn.new
  v.refs = make_in_place(v, name, ascending)
  v
end

.make_from_set(set) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/oinky.rb', line 413

def self.make_from_set(set)
  values = []
  set.each {|col|
    if col.is_a?(Symbol) or col.is_a?(String)
      values << {:column_name=>col.to_s, :sort_ascending=>true}
    elsif col.is_a? Hash
      name = (col[:column_name] || col[:name] || col[:column]).to_s
      ascending = true
      [:ascending, :sort_ascending].each {|k|
        ascending = false if (col.has_key?(k) and not col[k])
      }
      [:descending, :sort_descending].each {|k|
        ascending = false if col[k]
      }
      values << {:column_name=>name, :sort_ascending=>ascending}
    else
      raise OinkyException.new("Unrecognized index columnset entry: #{col.class}")
    end
  }
  ptr = IxColumnSet.new(values.size)
  ptr.refs = []
  values.each_with_index{|v, i|
    ptr.refs << make_in_place(ptr[i], v[:column_name], v[:sort_ascending])
  }
  ptr
end

.make_in_place(nv, name, ascending = true) ⇒ Object



391
392
393
394
395
# File 'lib/oinky.rb', line 391

def self.make_in_place(nv, name, ascending = true)
  cn = DB_string.make_in_place(nv[:column_name], name)
  nv[:sort_ascending] = ascending ? 1 : 0
  cn
end

Instance Method Details

#to_hObject



381
382
383
384
# File 'lib/oinky.rb', line 381

def to_h
  { :column_name=>self[:column_name].to_s,
    :sort_ascending=>(self[:sort_ascending] != 0) }
end