class Lockbox::Generators::AuditsGenerator

Public Instance Methods

adapter() click to toggle source

use connection_config instead of connection.adapter so database connection isn't needed

# File lib/generators/lockbox/audits_generator.rb, line 31
def adapter
  if ActiveRecord::VERSION::STRING.to_f >= 6.1
    ActiveRecord::Base.connection_db_config.adapter.to_s
  else
    ActiveRecord::Base.connection_config[:adapter].to_s
  end
end
copy_migration() click to toggle source
# File lib/generators/lockbox/audits_generator.rb, line 9
def copy_migration
  migration_template "migration.rb", "db/migrate/create_lockbox_audits.rb", migration_version: migration_version
  template "model.rb", "app/models/lockbox_audit.rb"
end
data_type() click to toggle source
# File lib/generators/lockbox/audits_generator.rb, line 18
def data_type
  case adapter
  when /postg/i # postgres, postgis
    "jsonb"
  when /mysql/i
    "json"
  else
    "text"
  end
end
migration_version() click to toggle source
# File lib/generators/lockbox/audits_generator.rb, line 14
def migration_version
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end