Class: TenantKit::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- TenantKit::Generators::InstallGenerator
- Includes:
- ActiveRecord::Generators::Migration
- Defined in:
- lib/generators/tenant_kit/install/install_generator.rb
Overview
Installs TenantKit into a host app: writes the initializer and, unless the tenant model already exists, scaffolds it plus a migration.
rails g tenant_kit:install
Instance Method Summary collapse
-
#create_initializer ⇒ Object
Writes config/initializers/tenant_kit.rb.
-
#create_tenant_model ⇒ Object
Creates the tenant model and its migration, unless it already exists or --skip-tenant-model was passed.
-
#show_readme ⇒ Object
Prints post-install guidance.
Instance Method Details
#create_initializer ⇒ Object
Writes config/initializers/tenant_kit.rb.
19 20 21 |
# File 'lib/generators/tenant_kit/install/install_generator.rb', line 19 def create_initializer template "initializer.rb.tt", "config/initializers/tenant_kit.rb" end |
#create_tenant_model ⇒ Object
Creates the tenant model and its migration, unless it already exists or --skip-tenant-model was passed.
25 26 27 28 29 30 31 32 |
# File 'lib/generators/tenant_kit/install/install_generator.rb', line 25 def create_tenant_model return if [:skip_tenant_model] return if tenant_model_exists? template "tenant_model.rb.tt", "app/models/#{tenant_singular}.rb" migration_template "tenant_migration.rb.tt", "db/migrate/create_#{tenant_plural}.rb" end |
#show_readme ⇒ Object
Prints post-install guidance.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/tenant_kit/install/install_generator.rb', line 35 def show_readme say "" say "TenantKit installed.", :green say " 1. Review config/initializers/tenant_kit.rb" say " 2. Add `belongs_to_tenant` to each tenant-owned model" say " 3. Add the tenant column to owned tables: rails g tenant_kit:migration Project" say " 4. Resolve the tenant in ApplicationController, e.g." say " set_current_tenant_by_subdomain(:#{tenant_singular}, :subdomain)" say "" end |