Class: FlyingTable::TableMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/flying_table/table_maker.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tables, delay_setup = false, &block) ⇒ TableMaker

Returns a new instance of TableMaker.



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/flying_table/table_maker.rb', line 2

def initialize(tables, delay_setup=false, &block)
  @tables    = tables.map{|name, cols| [name.to_s, cols]}
  @AR        = ActiveRecord
  @base      = @AR::Base
  @migration = @AR::Migration
  setup() unless delay_setup
  if block_given?
    yield(self, @AR)
    teardown()
  end
end

Class Method Details

.create(tables) ⇒ Object



13
# File 'lib/flying_table/table_maker.rb', line 13

def self.create(tables)  new(tables)    end

.destroy(tables) ⇒ Object



14
# File 'lib/flying_table/table_maker.rb', line 14

def self.destroy(tables) new(tables,true).teardown end

Instance Method Details

#setupObject



16
# File 'lib/flying_table/table_maker.rb', line 16

def setup()    @base.transaction{@migration.suppress_messages{create_tables}} end

#teardownObject



17
# File 'lib/flying_table/table_maker.rb', line 17

def teardown() @base.transaction{@migration.suppress_messages{drop_tables}}   end