Sha256: b999d992c49da191d5894edf8eb703623db720b278d40841141289d49ecb83d8

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

require "rails/generators/active_record"

module Lockbox
  module Generators
    class AuditsGenerator < Rails::Generators::Base
      include ActiveRecord::Generators::Migration
      source_root File.join(__dir__, "templates")

      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

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

      def data_type
        case adapter
        when /postg/i # postgres, postgis
          "jsonb"
        when /mysql/i
          "json"
        else
          "text"
        end
      end

      # use connection_config instead of connection.adapter
      # so database connection isn't needed
      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
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lockbox-1.4.1 lib/generators/lockbox/audits_generator.rb
lockbox-1.4.0 lib/generators/lockbox/audits_generator.rb
lockbox-1.3.3 lib/generators/lockbox/audits_generator.rb
lockbox-1.3.2 lib/generators/lockbox/audits_generator.rb
lockbox-1.3.1 lib/generators/lockbox/audits_generator.rb
lockbox-1.3.0 lib/generators/lockbox/audits_generator.rb
lockbox-1.2.0 lib/generators/lockbox/audits_generator.rb
lockbox-1.1.2 lib/generators/lockbox/audits_generator.rb
lockbox-1.1.1 lib/generators/lockbox/audits_generator.rb
lockbox-1.1.0 lib/generators/lockbox/audits_generator.rb
lockbox-1.0.0 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.8 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.7 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.6 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.5 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.4 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.3 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.2 lib/generators/lockbox/audits_generator.rb