Sha256: 5067b8de8f9545feb97f810c36c92f7599ba14f61e84f4ff04158e28b3a0ae0d

Contents?: true

Size: 921 Bytes

Versions: 19

Compression:

Stored size: 921 Bytes

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
        # use connection_config instead of connection.adapter
        # so database connection isn't needed
        case ActiveRecord::Base.connection_config[:adapter].to_s
        when /postg/i # postgres, postgis
          "jsonb"
        when /mysql/i
          "json"
        else
          "text"
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lockbox-0.6.1 lib/generators/lockbox/audits_generator.rb
lockbox-0.6.0 lib/generators/lockbox/audits_generator.rb
lockbox-0.5.0 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.9 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.8 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.7 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.6 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.5 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.4 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.3 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.2 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.1 lib/generators/lockbox/audits_generator.rb
lockbox-0.4.0 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.7 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.6 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.5 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.4 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.3 lib/generators/lockbox/audits_generator.rb
lockbox-0.3.2 lib/generators/lockbox/audits_generator.rb