Class: ActionPasskey::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActionPasskey::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/action_passkey/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_has_passkeys_to_user_model ⇒ Object
- #add_routes ⇒ Object
- #configure_importmap ⇒ Object
- #copy_controller_files ⇒ Object
- #copy_helper_file ⇒ Object
- #copy_initializer ⇒ Object
- #copy_javascript_files ⇒ Object
- #copy_passkey_migration ⇒ Object
- #copy_passkey_model ⇒ Object
- #migration_version ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
82 83 84 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 82 def self.next_migration_number(dirname) ActiveRecord::Generators::Base.next_migration_number(dirname) end |
Instance Method Details
#add_has_passkeys_to_user_model ⇒ Object
57 58 59 60 61 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 57 def add_has_passkeys_to_user_model return unless File.exist?(File.join(destination_root, "app/models/user.rb")) inject_into_class "app/models/user.rb", "User", " has_passkeys\n" end |
#add_routes ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 63 def add_routes route <<~RUBY resources :passkeys, only: :create resource :passkey_session, only: :create namespace :passkeys do resource :options, only: :create end namespace :passkey_sessions do resource :options, only: :create end RUBY end |
#configure_importmap ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 43 def configure_importmap return unless File.exist?(File.join(destination_root, "config/importmap.rb")) append_to_file "config/importmap.rb", <<~RUBY pin_all_from "app/javascript/helpers", under: "helpers" pin "@github/webauthn-json", to: "webauthn-json.js" RUBY end |
#copy_controller_files ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 21 def copy_controller_files copy_file "passkey_relying_party.rb", "app/controllers/concerns/passkey_relying_party.rb" copy_file "passkeys_controller.rb", "app/controllers/passkeys_controller.rb" copy_file "passkeys_options_controller.rb", "app/controllers/passkeys/options_controller.rb" copy_file "passkey_sessions_controller.rb", "app/controllers/passkey_sessions_controller.rb" copy_file "passkey_sessions_options_controller.rb", "app/controllers/passkey_sessions/options_controller.rb" end |
#copy_helper_file ⇒ Object
29 30 31 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 29 def copy_helper_file copy_file "passkeys_helper.rb", "app/helpers/passkeys_helper.rb" end |
#copy_initializer ⇒ Object
13 14 15 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 13 def copy_initializer template "action_passkey.rb", "config/initializers/action_passkey.rb" end |
#copy_javascript_files ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 33 def copy_javascript_files copy_file "passkey_registration_controller.js", "app/javascript/controllers/passkey_registration_controller.js" copy_file "passkey_authentication_controller.js", "app/javascript/controllers/passkey_authentication_controller.js" copy_file "passkey.js", "app/javascript/helpers/passkey.js" copy_file "post.js", "app/javascript/helpers/post.js" copy_file "headers.js", "app/javascript/helpers/headers.js" copy_file "webauthn-json.js", "vendor/javascript/webauthn-json.js" end |
#copy_passkey_migration ⇒ Object
53 54 55 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 53 def copy_passkey_migration migration_template "create_passkeys.rb", "db/migrate/create_passkeys.rb" end |
#copy_passkey_model ⇒ Object
17 18 19 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 17 def copy_passkey_model template "passkey.rb", "app/models/passkey.rb" end |
#migration_version ⇒ Object
78 79 80 |
# File 'lib/generators/action_passkey/install/install_generator.rb', line 78 def migration_version "[#{ActiveRecord::Migration.current_version}]" end |