class ActiverecordSettings::Generators::InstallGenerator

Installs ActiverecordSettings in a rails app.

Public Class Methods

next_migration_number(path) click to toggle source
# 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

Public Instance Methods

add_migrations() click to toggle source
# 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_migrations() click to toggle source
# 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

Protected Instance Methods

migration_version() click to toggle source
# File lib/generators/activerecord_settings/install_generator.rb, line 46
def migration_version
  major = ActiveRecord::VERSION::MAJOR
  if major >= 5
    "[#{major}.#{ActiveRecord::VERSION::MINOR}]"
  end
end