module Rodauth::Rails::Generators::MigrationHelpers

Attributes

migration_class_name[R]

Public Instance Methods

migration_template(source, destination = File.basename(source)) click to toggle source
Calls superclass method
# File lib/generators/rodauth/migration_helpers.rb, line 9
def migration_template(source, destination = File.basename(source))
  @migration_class_name = destination.chomp(".rb").camelize

  super source, File.join(db_migrate_path, destination)
end

Private Instance Methods

activerecord_adapter() click to toggle source
# File lib/generators/rodauth/migration_helpers.rb, line 26
def activerecord_adapter
  if ActiveRecord::Base.respond_to?(:connection_db_config)
    ActiveRecord::Base.connection_db_config.adapter
  else
    ActiveRecord::Base.connection_config.fetch(:adapter)
  end
end
db_migrate_path() click to toggle source
Calls superclass method
# File lib/generators/rodauth/migration_helpers.rb, line 40
def db_migrate_path
  return "db/migrate" unless ActiveRecord.version >= Gem::Version.new("5.0")

  super
end
erb_eval(content) click to toggle source
# File lib/generators/rodauth/migration_helpers.rb, line 59
def erb_eval(content)
  if ERB.version[/\d+\.\d+\.\d+/].to_s >= "2.2.0"
    ERB.new(content, trim_mode: "-").result(binding)
  else
    ERB.new(content, 0, "-").result(binding)
  end
end
migration_content() click to toggle source
# File lib/generators/rodauth/migration_helpers.rb, line 17
def migration_content
  migration_features
    .select { |feature| File.exist?("#{__dir__}/migration/#{feature}.erb") }
    .map { |feature| File.read("#{__dir__}/migration/#{feature}.erb") }
    .map { |content| erb_eval(content) }
    .join("\n")
    .indent(4)
end
migration_version() click to toggle source
# File lib/generators/rodauth/migration_helpers.rb, line 34
def migration_version
  return unless ActiveRecord.version >= Gem::Version.new("5.0")

  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end
primary_key_type(key = :id) click to toggle source
# File lib/generators/rodauth/migration_helpers.rb, line 46
def primary_key_type(key = :id)
  generators  = ::Rails.application.config.generators
  column_type = generators.options[:active_record][:primary_key_type]

  return unless column_type

  if key
    ", #{key}: :#{column_type}"
  else
    column_type
  end
end