Class: ActiverecordSettings::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/activerecord_settings/install_generator.rb

Overview

Installs ActiverecordSettings in a rails app.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



15
16
17
18
# File 'lib/generators/activerecord_settings/install_generator.rb', line 15

def self.next_migration_number(path)
  next_migration_number = current_migration_number(path) + 1
  ActiveRecord::Migration.next_migration_number(next_migration_number)
end

Instance Method Details

#add_migrationsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/activerecord_settings/install_generator.rb', line 20

def add_migrations
  template = "create_activerecord_settings"
  migration_dir = File.expand_path("db/migrate")
  if self.class.migration_exists?(migration_dir, template)
    ::Kernel.warn "Migration already exists: #{template}"
  else
    migration_template(
      "#{template}.rb.erb",
      "db/migrate/#{template}.rb",
      migration_version: migration_version
    )
  end
end

#run_migrationsObject



34
35
36
37
38
39
40
41
42
# File 'lib/generators/activerecord_settings/install_generator.rb', line 34

def run_migrations
  return if ENV["RAILS_ENV"] == 'test'
  run_migrations = options[:auto_run_migrations] || ['y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
  if run_migrations
    run 'bundle exec rake db:migrate'
  else
    puts 'Skipping rake db:migrate, don\'t forget to run it!'
  end
end