Class: SchemaPlus::Core::SchemaDump::Table
- Inherits:
-
Object
- Object
- SchemaPlus::Core::SchemaDump::Table
- Defined in:
- lib/schema_plus/core/schema_dump.rb
Defined Under Namespace
Instance Method Summary collapse
- #assemble(stream) ⇒ Object
-
#initialize(*args) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(*args) ⇒ Table
Returns a new instance of Table.
47 48 49 50 51 52 53 |
# File 'lib/schema_plus/core/schema_dump.rb', line 47 def initialize(*args) super self.columns ||= [] self.indexes ||= [] self.statements ||= [] self.trailer ||= [] end |
Instance Method Details
#assemble(stream) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/schema_plus/core/schema_dump.rb', line 55 def assemble(stream) stream.write " create_table #{pname.inspect}" stream.write ", #{}" unless .blank? stream.puts " do |t|" typelen = columns.map{|col| col.type.length}.max namelen = columns.map{|col| col.name.length}.max columns.each do |column| stream.write " " column.assemble(stream, typelen, namelen) stream.puts "" end statements.each do |statement| stream.puts " #{statement}" end stream.puts " end" indexes.each do |index| stream.write " add_index #{pname.inspect}, " index.assemble(stream) stream.puts "" end trailer.each do |statement| stream.puts " #{statement}" end stream.puts "" end |