class SQLAliasedList

Class container - a list of SQLObjects with aliases

Attributes

no_commas[W]

Public Class Methods

new( *list ) click to toggle source
# File lib/sqlobject.rb, line 195
def initialize ( *list )
    @list = _getList *list
end

Public Instance Methods

<<( *list ) click to toggle source
# File lib/sqlobject.rb, line 199
def << ( *list )
    @list += _getList *list
    return self 
end
[](i) click to toggle source
# File lib/sqlobject.rb, line 220
def [] (i)
    @list[i]
end
delete_if( &block ) click to toggle source
# File lib/sqlobject.rb, line 216
def delete_if ( &block )
    @list.delete_if &block
end
each( &block ) click to toggle source
# File lib/sqlobject.rb, line 212
def each ( &block )
    @list.each &block
end
each_with_index( &block ) click to toggle source
# File lib/sqlobject.rb, line 232
def each_with_index ( &block )
    @list.each_with_index &block
end
find( &block ) click to toggle source
# File lib/sqlobject.rb, line 224
def find ( &block )
    @list.find &block
end
length() click to toggle source
# File lib/sqlobject.rb, line 208
def length
    @list.length
end
push( *list ) click to toggle source
# File lib/sqlobject.rb, line 204
def push ( *list )
    @list += _getList( *list )
end
select( &block ) click to toggle source
# File lib/sqlobject.rb, line 228
def select ( &block )
    @list.each &block
end
to_s() click to toggle source
# File lib/sqlobject.rb, line 236
def to_s
    return @string  if @string
    arr = @list.map { |obj|  obj.to_s + ( obj.alias  ? " " + obj.alias.to_s  : "" ) }
    list_separator = @no_commas  ? ""  : ","
    @string = arr.join list_separator
end

Private Instance Methods

_getList( *list ) click to toggle source
# File lib/sqlobject.rb, line 245
def _getList ( *list )
    new_list = [ ]
     # If list is a hash of objects with aliases:
    if list.length == 1 && list[0].is_a?( Hash )
        new_list += _hash2array list[0]
     # If list is an array of objects:
    else
        new_list = list.map { |src|  SQLObject.get src }
    end
end
_hash2array( hash ) click to toggle source
# File lib/sqlobject.rb, line 256
def _hash2array ( hash )
    list = [ ]
    hash.each do |item, _alias|
        obj = SQLObject.get item
        obj.alias = _alias
        list << obj
    end
    return list
end