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
- #copy_migration ⇒ Object
- #copy_templates ⇒ Object
-
#encryption ⇒ Object
TODO remove default.
- #generate_model ⇒ Object
- #identity_column ⇒ Object
- #ip_column ⇒ Object
- #lockbox_method ⇒ Object
- #migration_version ⇒ Object
Instance Method Details
#copy_migration ⇒ Object
13 14 15 16 |
# File 'lib/generators/authtrail/install_generator.rb', line 13 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
18 19 20 |
# File 'lib/generators/authtrail/install_generator.rb', line 18 def copy_templates template "initializer.rb", "config/initializers/authtrail.rb" end |
#encryption ⇒ Object
TODO remove default
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/generators/authtrail/install_generator.rb', line 58 def encryption case [:encryption] when "lockbox", "activerecord", "none" [:encryption] when nil if [:lockbox] # TODO deprecation warning "lockbox" else "none" end else abort "Error: encryption must be lockbox, activerecord, or none" end end |
#generate_model ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/authtrail/install_generator.rb', line 22 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
37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/authtrail/install_generator.rb', line 37 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" end end |
#ip_column ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/authtrail/install_generator.rb', line 47 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 |
#lockbox_method ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/generators/authtrail/install_generator.rb', line 74 def lockbox_method if defined?(Lockbox::VERSION) && Lockbox::VERSION.to_i < 1 "encrypts" else "has_encrypted" end end |
#migration_version ⇒ Object
33 34 35 |
# File 'lib/generators/authtrail/install_generator.rb', line 33 def migration_version "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" end |