Class: MigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/tasks/helpers/migration_generator.rb

Overview

Implementation based on how paper_trail gem achieves similar result github.com/paper-trail-gem/paper_trail/blob/master/lib/generators/paper_trail/migration_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Needs to be reimplemented or throws unimplemented error



13
14
15
# File 'lib/tasks/helpers/migration_generator.rb', line 13

def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#generate_migration(migration_name, template_file, template_options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tasks/helpers/migration_generator.rb', line 17

def generate_migration(migration_name, template_file, template_options)
  migration_directory = File.expand_path("db/migrate")

  if self.class.migration_exists?(migration_directory, migration_name)
    raise "Can't generate migration #{migration_name} because it already exists."
  end

  @template_options = template_options
  migration_template(template_file,
                     "db/migrate/#{migration_name}.rb",
                     {})
end

#migration_versionObject



30
31
32
33
34
35
36
# File 'lib/tasks/helpers/migration_generator.rb', line 30

def migration_version
  format(
    "[%d.%d]",
    ::ActiveRecord::VERSION::MAJOR,
    ::ActiveRecord::VERSION::MINOR
  )
end