Class: CommaHeaven::Sqler::Columns

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

Direct Known Subclasses

AssociationColumns

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, export, options = {}) ⇒ Columns

Returns a new instance of Columns.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/comma-heaven/sqler/columns.rb', line 6

def initialize(model, export, options = {})
  @model    = model
  @export   = export
  @options  = options
  
  # Fill the array
  fill!
  
  # Sort by position
  # sort! { |a, b| a.position <=> b.position }
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



4
5
6
# File 'lib/comma-heaven/sqler/columns.rb', line 4

def index
  @index
end

#modelObject

Returns the value of attribute model.



4
5
6
# File 'lib/comma-heaven/sqler/columns.rb', line 4

def model
  @model
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/comma-heaven/sqler/columns.rb', line 4

def options
  @options
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/comma-heaven/sqler/columns.rb', line 4

def parent
  @parent
end

Instance Method Details

#join_clauseObject



49
50
51
# File 'lib/comma-heaven/sqler/columns.rb', line 49

def join_clause
  return ''
end

#joinsObject



22
23
24
# File 'lib/comma-heaven/sqler/columns.rb', line 22

def joins
  map(&:joins).compact.uniq.join(" ").gsub(/\n/, '').squeeze(' ')
end

#prefixObject



45
46
47
# File 'lib/comma-heaven/sqler/columns.rb', line 45

def prefix
  return ''
end

#selectObject



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

def select
  map(&:select).reject { |e| e.empty? }.join(', ')
end

#sql_asObject



26
27
28
# File 'lib/comma-heaven/sqler/columns.rb', line 26

def sql_as
  map(&:sql_as).flatten
end

#tableObject



30
31
32
# File 'lib/comma-heaven/sqler/columns.rb', line 30

def table
  model.table_name
end

#table_alias(method = :pluralize) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/comma-heaven/sqler/columns.rb', line 34

def table_alias(method = :pluralize)
  t = case method
    when :pluralize
      model.table_name
    else
      model.name.underscore
    end
  
  return prefix + [((parent && parent.parent) ? parent.table_alias(method) : nil), t, index].compact.join('_')
end