123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Thor::Actions::CreateFile
Instance Chain:
self, Thor::Actions::CreateFile
Inherits: Thor::Actions::CreateFile
  • ::Object
Defined in: railties/lib/rails/generators/actions/create_migration.rb

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#exists? (readonly)

Alias for #existing_migration.

[ GitHub ]

  
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 45

alias :exists? :existing_migration

#identical?Boolean (readonly)

[ GitHub ]

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

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

Instance Method Details

#existing_migration Also known as: #exists?

[ GitHub ]

  
# 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

#invoke!

[ GitHub ]

  
# 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_dir

[ GitHub ]

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

def migration_dir
  File.dirname(@destination)
end

#migration_file_name

[ GitHub ]

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

def migration_file_name
  @base.migration_file_name
end

#on_conflict_behavior (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 48

def on_conflict_behavior # :doc:
  options = base.options.merge(config)
  if identical?
    say_status :identical, :blue, relative_existing_migration
  elsif options[:force]
    say_status :remove, :green, relative_existing_migration
    say_status :create, :green
    unless pretend?
      ::FileUtils.rm_rf(existing_migration)
      yield
    end
  elsif options[:skip]
    say_status :skip, :yellow
  else
    say_status :conflict, :red
    raise Error, "Another migration is already named #{migration_file_name}: " \
      "#{existing_migration}. Use --force to replace this migration " \
      "or --skip to ignore conflicted file."
  end
end

#relative_existing_migration

[ GitHub ]

  
# 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!

[ GitHub ]

  
# 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

#say_status(status, color, message = relative_destination) (private)

[ GitHub ]

  
# File 'railties/lib/rails/generators/actions/create_migration.rb', line 69

def say_status(status, color, message = relative_destination) # :doc:
  base.shell.say_status(status, message, color) if config[:verbose]
end