Sha256: 2bc7427c28fc9731f9eb9f7bc016cf5c8a812508003dfd4b2fb2fae10d204042

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require "rails/generators/active_record"

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

      class_option :lockbox, type: :boolean

      def copy_migration
        migration_template "login_activities_migration.rb", "db/migrate/create_login_activities.rb", migration_version: migration_version
      end

      def copy_templates
        template "initializer.rb", "config/initializers/authtrail.rb"
      end

      def generate_model
        if lockbox?
          template "model_lockbox.rb", "app/models/login_activity.rb"
        else
          template "model.rb", "app/models/login_activity.rb"
        end
      end

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

      def identity_column
        if lockbox?
          "t.text :identity_ciphertext\n      t.string :identity_bidx, index: true"
        else
          "t.string :identity, index: true"
        end
      end

      def ip_column
        if lockbox?
          "t.text :ip_ciphertext\n      t.string :ip_bidx, index: true"
        else
          "t.string :ip, index: true"
        end
      end

      def lockbox?
        options[:lockbox]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authtrail-0.4.1 lib/generators/authtrail/install_generator.rb
authtrail-0.4.0 lib/generators/authtrail/install_generator.rb
authtrail-0.3.1 lib/generators/authtrail/install_generator.rb