Class: Lockbox::Generators::AuditsGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Lockbox::Generators::AuditsGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/lockbox/audits_generator.rb
Instance Method Summary collapse
-
#adapter ⇒ Object
use connection_config instead of connection.adapter so database connection isn’t needed.
- #copy_migration ⇒ Object
- #data_type ⇒ Object
- #migration_version ⇒ Object
Instance Method Details
#adapter ⇒ Object
use connection_config instead of connection.adapter so database connection isn’t needed
31 32 33 |
# File 'lib/generators/lockbox/audits_generator.rb', line 31 def adapter ActiveRecord::Base.connection_db_config.adapter.to_s end |
#copy_migration ⇒ Object
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_type ⇒ Object
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_version ⇒ Object
14 15 16 |
# File 'lib/generators/lockbox/audits_generator.rb', line 14 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end |