Class: Makitzo::Migrations::Generator

Inherits:
Object
  • Object
show all
Includes:
ApplicationAware, Paths
Defined in:
lib/makitzo/migrations/generator.rb

Instance Method Summary collapse

Methods included from Paths

#local_migration_path

Methods included from ApplicationAware

#app, #config, #logger, #store

Constructor Details

#initialize(app) ⇒ Generator

Returns a new instance of Generator.



6
7
8
# File 'lib/makitzo/migrations/generator.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#create_migration(name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/makitzo/migrations/generator.rb', line 10

def create_migration(name)
  @migration_name = name
  @migration_timestamp = Time.now.to_i
  @migration_directory = File.join(local_migration_path, "#{@migration_timestamp}_#{@migration_name}")
  @migration_class_name = @migration_name.camelize
  
  template = ERB.new(File.read(File.join(Makitzo::ROOT, 'templates', 'migration.erb')))
  
  FileUtils.mkdir_p(@migration_directory)
  
  migration_source = template.result(binding)
  File.open(File.join(@migration_directory, 'migration.rb'), 'w') { |f| f.write(migration_source) }
end