Class: Unmagic::Passkeys::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/unmagic/passkeys/install_generator.rb

Overview

Installs unmagic-passkeys into a host app: copies the credentials migration (matching the host's primary-key type), imports the JavaScript, and prints the remaining controller/route/view wiring to do.

Rails is referenced with a leading :: throughout: inside the Unmagic::Passkeys namespace a nested constant named Rails (0.2.0 had one for the routes macro) shadows the framework and breaks the generator.

Instance Method Summary collapse

Instance Method Details

#create_migration_file ⇒ Object



23
24
25
26
# File 'lib/generators/unmagic/passkeys/install_generator.rb', line 23

def create_migration_file
  migration_template "create_unmagic_passkeys_credentials.rb.tt",
    "db/migrate/create_unmagic_passkeys_credentials.rb"
end

#import_javascript ⇒ Object



28
29
30
31
32
33
34
# File 'lib/generators/unmagic/passkeys/install_generator.rb', line 28

def import_javascript
  application_js = "app/javascript/application.js"

  if File.exist?(File.join(destination_root, application_js))
    append_to_file application_js, %(import "unmagic/passkeys"\n)
  end
end

#show_post_install ⇒ Object



36
37
38
# File 'lib/generators/unmagic/passkeys/install_generator.rb', line 36

def show_post_install
  readme "POST_INSTALL" if behavior == :invoke
end