Class: MatViews::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MatViews::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/mat_views/install/install_generator.rb
Overview
Rails generator that installs MatViews into a host application by:
-
Copying migrations for definitions and run-tracking tables.
-
Creating an initializer at
config/initializers/mat_views.rb. -
Printing a success message with next steps.
Class Method Summary collapse
-
.next_migration_number(path) ⇒ String
Computes the next migration number for copied migrations.
Instance Method Summary collapse
-
#copy_migrations ⇒ void
Copies all required migrations into the host app.
-
#create_initializer ⇒ void
Creates the engine initializer in the host app.
-
#expand_path ⇒ String
Directory containing template files for the generator.
-
#show_success_message ⇒ void
Prints a success message after installation.
Class Method Details
.next_migration_number(path) ⇒ String
Computes the next migration number for copied migrations.
Required by Rails to generate timestamped migration filenames.
81 82 83 |
# File 'lib/generators/mat_views/install/install_generator.rb', line 81 def self.next_migration_number(path) ActiveRecord::Generators::Base.next_migration_number(path) end |
Instance Method Details
#copy_migrations ⇒ void
This method returns an undefined value.
Copies all required migrations into the host app.
50 51 52 53 |
# File 'lib/generators/mat_views/install/install_generator.rb', line 50 def copy_migrations migration_template 'create_mat_view_definitions.rb', 'db/migrate/create_mat_view_definitions.rb' migration_template 'create_mat_view_runs.rb', 'db/migrate/create_mat_view_runs.rb' end |
#create_initializer ⇒ void
This method returns an undefined value.
Creates the engine initializer in the host app.
60 61 62 |
# File 'lib/generators/mat_views/install/install_generator.rb', line 60 def create_initializer copy_file 'mat_views_initializer.rb', 'config/initializers/mat_views.rb' end |
#expand_path ⇒ String
Directory containing template files for the generator.
39 |
# File 'lib/generators/mat_views/install/install_generator.rb', line 39 source_root File.('templates', __dir__) |
#show_success_message ⇒ void
This method returns an undefined value.
Prints a success message after installation.
69 70 71 |
# File 'lib/generators/mat_views/install/install_generator.rb', line 69 def say "\n✅ MatViews installed! Don't forget to run: rails db:migrate\n", :green end |