class HecksAdapters::SQLDatabase::CLI::MigrationBuilder

Attributes

generator[R]

Public Class Methods

new(generator, specification) click to toggle source
# File lib/cli/migration_builder.rb, line 5
def initialize(generator, specification)
  @generator = generator
  @schema = HecksAdapters::SQLDatabase::Schema.factory(specification)
end

Public Instance Methods

call() click to toggle source
# File lib/cli/migration_builder.rb, line 10
def call
  generate_migrations
  self
end
columns() click to toggle source
# File lib/cli/migration_builder.rb, line 19
def columns
  @table.columns
end
table_name() click to toggle source
# File lib/cli/migration_builder.rb, line 15
def table_name
  @table.name
end
tables() click to toggle source
# File lib/cli/migration_builder.rb, line 23
def tables
  @schema.tables
end

Private Instance Methods

file_name(index, object) click to toggle source
# File lib/cli/migration_builder.rb, line 31
def file_name(index, object)
  "#{index}_create_#{table_name}.rb"
end
generate_migrations() click to toggle source
# File lib/cli/migration_builder.rb, line 35
def generate_migrations
  tables.each.with_index(1) do |table, index|
    @table = table
    @generator.template(
      "migration.rb.tt",
      "db/migrate/" + file_name(index, table)
    )
  end
end