Sha256: f457c278e3b5aced2e9986761f3a758ccacc6bf7cc2f651955a541807bc15cdb
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
# frozen_string_literal: true require "rails/generators" require "rails/generators/active_record" module PaperTrailAssociationTracking # Installs PaperTrail in a rails app. class InstallGenerator < ::Rails::Generators::Base include ::Rails::Generators::Migration # Class names of MySQL adapters. # - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`. # - `Mysql2Adapter` - Used by `mysql2` gem. MYSQL_ADAPTERS = [ "ActiveRecord::ConnectionAdapters::MysqlAdapter", "ActiveRecord::ConnectionAdapters::Mysql2Adapter" ].freeze source_root File.expand_path("../templates", __FILE__) desc "Generates (but does not run) a migration to add a versions table." def create_migrations add_paper_trail_migration("create_version_associations") add_paper_trail_migration("add_transaction_id_column_to_versions") end def create_initializer create_file( "config/initializers/paper_trail.rb", "PaperTrail.config.track_associations = #{!!options.with_associations?}\n", "PaperTrail.config.association_reify_error_behaviour = :error" ) end def self.next_migration_number(dirname) ::ActiveRecord::Generators::Base.next_migration_number(dirname) end protected def add_paper_trail_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 ) end end private def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
paper_trail-association_tracking-2.1.0 | lib/generators/paper_trail_association_tracking/install_generator.rb |