Class: Maquina::Generators::ClaveGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Maquina::Generators::ClaveGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/maquina/clave/clave_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#add_migrations ⇒ Object
12.
-
#add_routes ⇒ Object
11.
-
#configure_application_controller ⇒ Object
10.
-
#create_controllers ⇒ Object
2.
-
#create_helper ⇒ Object
4.
-
#create_job ⇒ Object
5.
-
#create_locale_files ⇒ Object
7.
-
#create_mailer ⇒ Object
3.
-
#create_models ⇒ Object
1.
-
#create_test_helper ⇒ Object
9.
-
#create_views ⇒ Object
6.
-
#show_post_install ⇒ Object
13.
Class Method Details
.next_migration_number(dirname) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 18 def self.next_migration_number(dirname) current = Time.now.utc.strftime("%Y%m%d%H%M%S") if @prev_migration_nr && @prev_migration_nr >= current current = @prev_migration_nr.succ end existing = Dir.glob("#{dirname}/[0-9]*_*.rb").map { |f| File.basename(f).split("_", 2).first } max_existing = existing.max if max_existing && max_existing >= current current = max_existing.succ end @prev_migration_nr = current end |
Instance Method Details
#add_migrations ⇒ Object
-
Migrations
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 149 def add_migrations migration_template "migration_create_accounts.rb.tt", "db/migrate/create_accounts.rb" migration_template "migration_create_users.rb.tt", "db/migrate/create_users.rb" migration_template "migration_create_sessions.rb.tt", "db/migrate/create_sessions.rb" migration_template "migration_create_email_verifications.rb.tt", "db/migrate/create_email_verifications.rb" end |
#add_routes ⇒ Object
-
Routes
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 126 def add_routes route_content = <<~RUBY # Authentication routes (generated by maquina:clave) resource :session, only: [:new, :create, :destroy] do resource :verification, only: [:new, :create], controller: "session/verifications" resource :verification_resend, only: [:create], controller: "session/verification_resends" end RUBY unless [:skip_registration] route_content += <<~RUBY resource :registration, only: [:new, :create] do resource :verification, only: [:new, :create], controller: "registration/verifications" resource :verification_resend, only: [:create], controller: "registration/verification_resends" end RUBY end route route_content end |
#configure_application_controller ⇒ Object
-
Include Authentication in ApplicationController
118 119 120 121 122 123 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 118 def configure_application_controller sentinel = "class ApplicationController < ActionController::Base\n" inject_into_file "app/controllers/application_controller.rb", " include Authentication\n", after: sentinel end |
#create_controllers ⇒ Object
-
Controllers
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 45 def create_controllers template "app/controllers/concerns/authentication.rb.tt", "app/controllers/concerns/authentication.rb" template "app/controllers/sessions_controller.rb.tt", "app/controllers/sessions_controller.rb" template "app/controllers/session/verifications_controller.rb.tt", "app/controllers/session/verifications_controller.rb" template "app/controllers/session/verification_resends_controller.rb.tt", "app/controllers/session/verification_resends_controller.rb" unless [:skip_registration] template "app/controllers/registrations_controller.rb.tt", "app/controllers/registrations_controller.rb" template "app/controllers/registration/verifications_controller.rb.tt", "app/controllers/registration/verifications_controller.rb" template "app/controllers/registration/verification_resends_controller.rb.tt", "app/controllers/registration/verification_resends_controller.rb" end end |
#create_helper ⇒ Object
-
Helper
72 73 74 75 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 72 def create_helper template "app/helpers/authentication_helper.rb.tt", "app/helpers/authentication_helper.rb" end |
#create_job ⇒ Object
-
Job
78 79 80 81 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 78 def create_job template "app/jobs/authentication_cleanup_job.rb.tt", "app/jobs/authentication_cleanup_job.rb" end |
#create_locale_files ⇒ Object
-
Locale files
106 107 108 109 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 106 def create_locale_files copy_file "config/locales/clave.en.yml", "config/locales/clave.en.yml" copy_file "config/locales/clave.es.yml", "config/locales/clave.es.yml" end |
#create_mailer ⇒ Object
-
Mailer
66 67 68 69 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 66 def create_mailer template "app/mailers/verification_mailer.rb.tt", "app/mailers/verification_mailer.rb" end |
#create_models ⇒ Object
-
Models
36 37 38 39 40 41 42 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 36 def create_models template "app/models/account.rb.tt", "app/models/account.rb" template "app/models/current.rb.tt", "app/models/current.rb" template "app/models/session.rb.tt", "app/models/session.rb" template "app/models/email_verification.rb.tt", "app/models/email_verification.rb" template "app/models/user.rb.tt", "app/models/user.rb" end |
#create_test_helper ⇒ Object
-
Test helper
112 113 114 115 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 112 def create_test_helper template "test/test_helpers/session_test_helper.rb.tt", "test/test_helpers/session_test_helper.rb" end |
#create_views ⇒ Object
-
Views
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 84 def create_views return if [:skip_views] template "app/views/sessions/new.html.erb.tt", "app/views/sessions/new.html.erb" template "app/views/session/verifications/new.html.erb.tt", "app/views/session/verifications/new.html.erb" unless [:skip_registration] template "app/views/registrations/new.html.erb.tt", "app/views/registrations/new.html.erb" template "app/views/registration/verifications/new.html.erb.tt", "app/views/registration/verifications/new.html.erb" end template "app/views/verification_mailer/verification_code.html.erb.tt", "app/views/verification_mailer/verification_code.html.erb" template "app/views/verification_mailer/verification_code.text.erb.tt", "app/views/verification_mailer/verification_code.text.erb" end |
#show_post_install ⇒ Object
-
Post-install message
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/generators/maquina/clave/clave_generator.rb', line 161 def show_post_install return if [:quiet] say "" say "Clave authentication has been installed!", :green say "" say "Next steps:", :yellow say " 1. rails db:migrate # Run migrations" say " 2. rails server # Start the app" say " 3. Visit /session/new # Sign-in page" unless [:skip_registration] say " 4. Visit /registration/new # Sign-up page" end say "" say "Optional:", :yellow say " - Edit app/controllers/concerns/authentication.rb to customize redirect URLs" say " - Edit config/locales/clave.*.yml to customize messages" say " - Set up Action Mailer for email delivery (letter_opener for development)" say "" end |