Class: Rails::Generators::Actions::CreateMigration

Inherits:
Thor::Actions::CreateFile
  • Object
show all
Defined in:
railties/lib/rails/generators/actions/create_migration.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#existing_migrationObject Also known as: exists?



41
42
43
44
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 41

def existing_migration
  @existing_migration ||= @base.class.migration_exists?(migration_dir, migration_file_name) ||
    File.exist?(@destination) && @destination
end

#identical?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 18

def identical?
  exists? && File.binread(existing_migration) == render
end

#invoke!Object



22
23
24
25
26
27
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 22

def invoke!
  return super if pretend?

  invoked_file = super
  File.exist?(@destination) ? invoked_file : relative_existing_migration
end

#migration_dirObject



10
11
12
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 10

def migration_dir
  File.dirname(@destination)
end

#migration_file_nameObject



14
15
16
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 14

def migration_file_name
  @base.migration_file_name
end

#relative_existing_migrationObject



37
38
39
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 37

def relative_existing_migration
  base.relative_to_original_destination_root(existing_migration)
end

#revoke!Object



29
30
31
32
33
34
35
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 29

def revoke!
  say_destination = exists? ? relative_existing_migration : relative_destination
  say_status :remove, :red, say_destination
  return unless exists?
  ::FileUtils.rm_rf(existing_migration) unless pretend?
  existing_migration
end