class FlyingTable::TableMaker
Public Class Methods
create(tables)
click to toggle source
# File lib/flying_table/table_maker.rb, line 13 def self.create(tables) new(tables) end
destroy(tables)
click to toggle source
# File lib/flying_table/table_maker.rb, line 14 def self.destroy(tables) new(tables,true).teardown end
new(tables, delay_setup=false) { |self, @AR| ... }
click to toggle source
# 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
Public Instance Methods
setup()
click to toggle source
# File lib/flying_table/table_maker.rb, line 16 def setup() @base.transaction{@migration.suppress_messages{create_tables}} end
teardown()
click to toggle source
# File lib/flying_table/table_maker.rb, line 17 def teardown() @base.transaction{@migration.suppress_messages{drop_tables}} end
Private Instance Methods
create_columns(t,columns)
click to toggle source
# File lib/flying_table/table_maker.rb, line 30 def create_columns(t,columns) columns.each{|name,type| t.send(type,name) } end
create_tables()
click to toggle source
def info() “To be implemented…”
# File lib/flying_table/table_maker.rb, line 23 def create_tables @tables.each do |name, columns| Object.const_set(name.classify, Class.new(ActiveRecord::Base)) @migration.create_table(name.pluralize){ |t| create_columns(t,columns)} end end
drop_tables()
click to toggle source
# File lib/flying_table/table_maker.rb, line 32 def drop_tables @tables.each do |name, columns| Object.send(:remove_const, name.classify) @migration.drop_table(name.pluralize) end end