lib/generators/authtrail/install_generator.rb in authtrail-0.5.0 vs lib/generators/authtrail/install_generator.rb in authtrail-0.6.0
- old
+ new
@@ -4,13 +4,11 @@
module Generators
class InstallGenerator < Rails::Generators::Base
include ActiveRecord::Generators::Migration
source_root File.join(__dir__, "templates")
- class_option :encryption, type: :string
- # deprecated
- class_option :lockbox, type: :boolean
+ class_option :encryption, type: :string, required: true
def copy_migration
encryption # ensure valid
migration_template "login_activities_migration.rb", "db/migrate/create_login_activities.rb", migration_version: migration_version
end
@@ -37,37 +35,31 @@
def identity_column
case encryption
when "lockbox"
"t.text :identity_ciphertext\n t.string :identity_bidx, index: true"
else
- # TODO add limit: 510 for Active Record encryption + MySQL?
- "t.string :identity, index: true"
+ if encryption == "activerecord" && mysql?
+ "t.string :identity, limit: 510, index: true"
+ else
+ "t.string :identity, index: true"
+ end
end
end
def ip_column
case encryption
when "lockbox"
"t.text :ip_ciphertext\n t.string :ip_bidx, index: true"
else
- # TODO add limit: 510 for Active Record encryption + MySQL?
"t.string :ip, index: true"
end
end
- # TODO remove default
def encryption
case options[:encryption]
when "lockbox", "activerecord", "none"
options[:encryption]
- when nil
- if options[:lockbox]
- # TODO deprecation warning
- "lockbox"
- else
- "none"
- end
else
abort "Error: encryption must be lockbox, activerecord, or none"
end
end
@@ -75,9 +67,17 @@
if defined?(Lockbox::VERSION) && Lockbox::VERSION.to_i < 1
"encrypts"
else
"has_encrypted"
end
+ end
+
+ def mysql?
+ adapter =~ /mysql|trilogy/i
+ end
+
+ def adapter
+ ActiveRecord::Base.connection_db_config.adapter.to_s
end
end
end
end