Class: JwtAuthEngine::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- JwtAuthEngine::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/jwt_auth_engine/install/install_generator.rb
Overview
Generator that installs initializer, migration, and model concern wiring.
Constant Summary collapse
- AUTH_MODEL_CONCERN_INCLUDE =
'include JwtAuthEngine::AuthModelConcern'
Class Method Summary collapse
Instance Method Summary collapse
- #copy_migration ⇒ Object
- #create_auth_model_concern ⇒ Object
- #create_initializer ⇒ Object
- #inject_auth_model_concern ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/generators/jwt_auth_engine/install/install_generator.rb', line 59 def self.next_migration_number(dirname) if defined?(ActiveRecord::Generators::Base) ActiveRecord::Generators::Base.next_migration_number(dirname) else Time.now.utc.strftime('%Y%m%d%H%M%S') end end |
Instance Method Details
#copy_migration ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/jwt_auth_engine/install/install_generator.rb', line 35 def copy_migration @auth_model_table = [:auth_model].tableize @identifier_field = [:identifier_field].to_sym @password_digest_field = :"#{[:password_field]}_digest" @migration_class_name = "AddJwtAuthEngineColumnsTo#{@auth_model_table.classify.tr('::', '')}" @migration_version = host_active_record_migration_version migration_template( 'add_jwt_auth_engine_columns_migration.rb.tt', "db/migrate/add_jwt_auth_engine_columns_to_#{@auth_model_table}.rb" ) end |
#create_auth_model_concern ⇒ Object
48 49 50 |
# File 'lib/generators/jwt_auth_engine/install/install_generator.rb', line 48 def create_auth_model_concern template 'auth_model_concern.rb.tt', 'app/models/concerns/jwt_auth_engine/auth_model_concern.rb' end |
#create_initializer ⇒ Object
28 29 30 31 32 33 |
# File 'lib/generators/jwt_auth_engine/install/install_generator.rb', line 28 def create_initializer @auth_model = [:auth_model] @identifier_field = [:identifier_field].to_sym @password_field = [:password_field].to_sym template 'jwt_auth_engine_initializer.rb.tt', 'config/initializers/jwt_auth_engine.rb' end |
#inject_auth_model_concern ⇒ Object
52 53 54 55 56 57 |
# File 'lib/generators/jwt_auth_engine/install/install_generator.rb', line 52 def inject_auth_model_concern return warn_missing_auth_model_file unless File.exist?(auth_model_path) return note_existing_auth_model_concern if auth_model_concern_included? inject_into_class auth_model_path, [:auth_model], " #{AUTH_MODEL_CONCERN_INCLUDE}\n\n" end |