Class: ImmigrationGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/immigration_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_immigration_fileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/immigration_generator.rb', line 4

def create_immigration_file
  Rails.application.eager_load!
  @keys, warnings = Immigrant::KeyFinder.new.infer_keys
  warnings.values.each{ |warning| $stderr.puts "WARNING: #{warning}" }
  @keys.each do |key|
    next unless key.options[:dependent] == :delete
    $stderr.puts "NOTICE: #{key.options[:name]} has ON DELETE CASCADE. You should remove the :dependent option from the association to take advantage of this."
  end
  if @keys.present?
    migration_template Immigrant::TEMPLATE, "db/migrate/#{file_name}.rb"
  else
    puts 'Nothing to do'
  end
end

#migration_versionObject



21
22
23
24
25
# File 'lib/generators/immigration_generator.rb', line 21

def migration_version
  if supports_versioning?
    "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
  end
end

#supports_versioning?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/generators/immigration_generator.rb', line 27

def supports_versioning?
  Rails.version >= '5'
end