Class: TenantKit::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
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

Instance Method Details

#create_initializerObject

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_modelObject

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 options[: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_readmeObject

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