Class: CommaHeaven::Sqler::Column

Inherits:
Struct
  • Object
show all
Defined in:
lib/comma-heaven/sqler/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#asObject

Returns the value of attribute as

Returns:

  • (Object)

    the current value of as



5
6
7
# File 'lib/comma-heaven/sqler/column.rb', line 5

def as
  @as
end

#attributeObject

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



5
6
7
# File 'lib/comma-heaven/sqler/column.rb', line 5

def attribute
  @attribute
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



5
6
7
# File 'lib/comma-heaven/sqler/column.rb', line 5

def parent
  @parent
end

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



5
6
7
# File 'lib/comma-heaven/sqler/column.rb', line 5

def position
  @position
end

Instance Method Details

#joinsObject



12
13
14
15
16
# File 'lib/comma-heaven/sqler/column.rb', line 12

def joins
  sql = join_clause
  sql << " AND #{table_alias}.#{association.klass.primary_key} IN (SELECT #{association.klass.primary_key} FROM #{association.quoted_table_name} WHERE #{model.send(:sanitize_sql, association.options[:conditions])})" if parent.respond_to?(:association) && association.options[:conditions]
  sql.gsub(/\n/, '').squeeze(' ').strip
end

#selectObject



8
9
10
# File 'lib/comma-heaven/sqler/column.rb', line 8

def select
  "#{table_alias}.#{attribute} AS #{quote(sql_as)}"
end

#sql_asObject



18
19
20
21
# File 'lib/comma-heaven/sqler/column.rb', line 18

def sql_as
  return as % index if as
  return [table_alias(:singularize).gsub(/^_+/, ''), attribute].compact.join('_')
end