Class: Authtrail::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Authtrail::Generators::InstallGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/authtrail/install_generator.rb
Instance Method Summary collapse
- #adapter ⇒ Object
- #copy_migration ⇒ Object
- #copy_templates ⇒ Object
- #encryption ⇒ Object
- #generate_model ⇒ Object
- #identity_column ⇒ Object
- #ip_column ⇒ Object
- #lockbox_method ⇒ Object
- #migration_version ⇒ Object
- #mysql? ⇒ Boolean
Instance Method Details
#adapter ⇒ Object
78 79 80 |
# File 'lib/generators/authtrail/install_generator.rb', line 78 def adapter ActiveRecord::Base.connection_db_config.adapter.to_s end |
#copy_migration ⇒ Object
11 12 13 14 |
# File 'lib/generators/authtrail/install_generator.rb', line 11 def copy_migration encryption # ensure valid migration_template "login_activities_migration.rb", "db/migrate/create_login_activities.rb", migration_version: migration_version end |
#copy_templates ⇒ Object
16 17 18 |
# File 'lib/generators/authtrail/install_generator.rb', line 16 def copy_templates template "initializer.rb", "config/initializers/authtrail.rb" end |
#encryption ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/generators/authtrail/install_generator.rb', line 57 def encryption case [:encryption] when "lockbox", "activerecord", "none" [:encryption] else abort "Error: encryption must be lockbox, activerecord, or none" end end |
#generate_model ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/generators/authtrail/install_generator.rb', line 20 def generate_model case encryption when "lockbox" template "model_lockbox.rb", "app/models/login_activity.rb", lockbox_method: lockbox_method when "activerecord" template "model_activerecord.rb", "app/models/login_activity.rb" else template "model_none.rb", "app/models/login_activity.rb" end end |
#identity_column ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/authtrail/install_generator.rb', line 35 def identity_column case encryption when "lockbox" "t.text :identity_ciphertext\n t.string :identity_bidx, index: true" else if encryption == "activerecord" && mysql? "t.string :identity, limit: 510, index: true" else "t.string :identity, index: true" end end end |
#ip_column ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/generators/authtrail/install_generator.rb', line 48 def ip_column case encryption when "lockbox" "t.text :ip_ciphertext\n t.string :ip_bidx, index: true" else "t.string :ip, index: true" end end |
#lockbox_method ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/generators/authtrail/install_generator.rb', line 66 def lockbox_method if defined?(Lockbox::VERSION) && Lockbox::VERSION.to_i < 1 "encrypts" else "has_encrypted" end end |
#migration_version ⇒ Object
31 32 33 |
# File 'lib/generators/authtrail/install_generator.rb', line 31 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end |
#mysql? ⇒ Boolean
74 75 76 |
# File 'lib/generators/authtrail/install_generator.rb', line 74 def mysql? adapter =~ /mysql|trilogy/i end |