class Shaf::Generator::Migration::CreateTable

Public Instance Methods

compile_changes() click to toggle source
# File lib/shaf/generator/migration/create_table.rb, line 22
def compile_changes
  add_change create_table_change
end
compile_migration_name() click to toggle source
# File lib/shaf/generator/migration/create_table.rb, line 18
def compile_migration_name
  "create_#{table_name}_table"
end
create_table_change() click to toggle source
# File lib/shaf/generator/migration/create_table.rb, line 26
def create_table_change
  cols = ["primary_key :id"]
  cols += ["DateTime :created_at", "DateTime :updated_at"] if add_timestamp_columns?
  cols += args[1..-1].map { |s| column_def(s) }
  [
    "create_table(:#{table_name}) do",
    *cols.map { |col| col.prepend("  ") }, # indent body with 2 spaces
    "end\n\n"
  ]
end
table_name() click to toggle source
# File lib/shaf/generator/migration/create_table.rb, line 14
def table_name
  args.first || ""
end
validate_args() click to toggle source
# File lib/shaf/generator/migration/create_table.rb, line 9
def validate_args
  return unless table_name.empty?
  raise "Please provide a table name when generation a create table migration"
end