Class: FlyingTable::TableMaker
- Inherits:
-
Object
- Object
- FlyingTable::TableMaker
- Defined in:
- lib/flying_table/table_maker.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tables, delay_setup = false, &block) ⇒ TableMaker
constructor
A new instance of TableMaker.
- #setup ⇒ Object
- #teardown ⇒ Object
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
#setup ⇒ Object
16 |
# File 'lib/flying_table/table_maker.rb', line 16 def setup() @base.transaction{@migration.{create_tables}} end |
#teardown ⇒ Object
17 |
# File 'lib/flying_table/table_maker.rb', line 17 def teardown() @base.transaction{@migration.{drop_tables}} end |