Class: RBase::SchemaDumper
- Inherits:
-
Object
- Object
- RBase::SchemaDumper
- Defined in:
- lib/rbase/schema_dumper.rb
Class Method Summary collapse
-
.dump(table) ⇒ Object
Produce ruby schema for a given table.
Class Method Details
.dump(table) ⇒ Object
Produce ruby schema for a given table.
Parameters
table - instance of RBase::Table opened
Example
users = RBase::Table.open('users')
File.open('users.dump.rb', 'w') do |f|
f.write RBase::SchemaDumper.dump(users)
end
users.close
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rbase/schema_dumper.rb', line 17 def self.dump(table) output = '' output << "RBase.create_table :#{table.name} do |t|\n" table.columns.each do |column| output << " t.column '#{column.name}', '#{column.type}', :size => #{column.size}#{ (column.decimal && column.decimal > 0) ? ", :decimal => #{column.decimal}" : ''}\n" end output << "end\n" end |