Class: Lockbox::Generators::AuditsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/lockbox/audits_generator.rb

Instance Method Summary collapse

Instance Method Details

#adapterObject

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



31
32
33
34
35
36
37
# 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_migrationObject



9
10
11
12
# 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_typeObject



18
19
20
21
22
23
24
25
26
27
# 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_versionObject



14
15
16
# File 'lib/generators/lockbox/audits_generator.rb', line 14

def migration_version
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end