Class: Theman::Agency::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/theman/agency/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, columns, temporary = nil, on_commit = nil) ⇒ Table

Returns a new instance of Table.



4
5
6
7
8
9
# File 'lib/theman/agency/table.rb', line 4

def initialize(name, columns, temporary = nil, on_commit = nil)
  @name       = name
  @columns    = columns
  @temporary  = temporary
  @on_commit  = on_commit
end

Instance Method Details

#to_sql(sql = []) ⇒ Object

:nodoc



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/theman/agency/table.rb', line 11

def to_sql(sql = []) #:nodoc
  sql << ["CREATE"]
  sql << "TEMPORARY TABLE" unless @temporary == false
  sql << @name
  sql << "(#{@columns})"
  unless @on_commit.nil?
    sql << "ON COMMIT"
    sql << @on_commit.to_s.upcase.gsub(/_/," ")
  end
  sql.join(" ")
end