Class: Schemer::ActiveRecord::Migrator

Inherits:
Object
  • Object
show all
Defined in:
lib/schemer/active_record.rb

Class Method Summary collapse

Class Method Details

.migration(klass) ⇒ Object

Outputs the Rails migration for the schema defined in the given class.

Outputs an empty string if no schema is defined on the class.



86
87
88
89
90
91
92
93
94
# File 'lib/schemer/active_record.rb', line 86

def self.migration(klass)
  return nil unless klass.respond_to?(:schema_columns)

  "create_table :#{klass.table_name} do |t|\n" +
  (klass.schema_columns.keys - klass.protected_columns).collect do |column| 
    "  t.#{klass.schema_columns[column]} :#{column}"
  end.join("\n") +
  "\nend"
end