Class: TempTable::Create
- Inherits:
-
Object
- Object
- TempTable::Create
- Defined in:
- lib/temp_table/create.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
-
#initialize(table_name, columns) ⇒ Create
constructor
A new instance of Create.
- #perform ⇒ Object
Constructor Details
#initialize(table_name, columns) ⇒ Create
Returns a new instance of Create.
7 8 9 10 11 |
# File 'lib/temp_table/create.rb', line 7 def initialize(table_name, columns) super() @table_name = table_name @columns = columns end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/temp_table/create.rb', line 5 def columns @columns end |
#table_name ⇒ Object
Returns the value of attribute table_name.
5 6 7 |
# File 'lib/temp_table/create.rb', line 5 def table_name @table_name end |
Instance Method Details
#perform ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/temp_table/create.rb', line 13 def perform column_definitions = columns.map { |name, type| "#{name} #{type}" }.join(", ") if column_definitions.empty? ActiveRecord::Base.connection.execute <<-SQL.squish CREATE TEMPORARY IF NOT EXISTS #{@table_name} ( id SERIAL PRIMARY KEY ); SQL else ActiveRecord::Base.connection.execute <<-SQL.squish CREATE TEMPORARY TABLE #{@table_name} ( id SERIAL PRIMARY KEY, #{column_definitions} ); SQL end end |