class Forced::InstallGenerator

Constants

MYSQL_ADAPTERS

Public Class Methods

next_migration_number(dirname) click to toggle source
# File lib/generators/forced/install_generator.rb, line 23
def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Public Instance Methods

create_migration_file() click to toggle source
# File lib/generators/forced/install_generator.rb, line 19
def create_migration_file
  add_forced_app_migration('create_forced_tables')
end

Protected Instance Methods

add_forced_app_migration(template) click to toggle source
# File lib/generators/forced/install_generator.rb, line 29
def add_forced_app_migration(template)
  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,
      forced_table_options: forced_table_options
    )
  end
end

Private Instance Methods

forced_table_options() click to toggle source
# File lib/generators/forced/install_generator.rb, line 57
def forced_table_options
  if mysql?
    ', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }'
  else
    ""
  end
end
migration_version() click to toggle source
# File lib/generators/forced/install_generator.rb, line 46
def migration_version
  major = ActiveRecord::VERSION::MAJOR
  if major >= 5
    "[#{major}.#{ActiveRecord::VERSION::MINOR}]"
  end
end
mysql?() click to toggle source
# File lib/generators/forced/install_generator.rb, line 53
def mysql?
  MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
end