Class: RlsMultiTenant::Generators::ModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rls_multi_tenant/generators/model/model_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(args, *options) ⇒ ModelGenerator

Returns a new instance of ModelGenerator.



13
14
15
16
# File 'lib/rls_multi_tenant/generators/model/model_generator.rb', line 13

def initialize(args, *options)
  super
  @attributes = parse_attributes!
end

Instance Method Details

#create_migrationObject



24
25
26
# File 'lib/rls_multi_tenant/generators/model/model_generator.rb', line 24

def create_migration
  template 'migration.rb', File.join('db/migrate', "#{migration_file_name}.rb")
end

#create_model_fileObject



20
21
22
# File 'lib/rls_multi_tenant/generators/model/model_generator.rb', line 20

def create_model_file
  template 'model.rb', File.join('app/models', "#{model_name.underscore}.rb")
end

#show_instructionsObject



28
29
30
31
32
33
34
35
36
# File 'lib/rls_multi_tenant/generators/model/model_generator.rb', line 28

def show_instructions
  say "\n#{'=' * 60}", :green
  say "Multi-tenant model '#{model_name}' created successfully!", :green
  say '=' * 60, :green
  say "\nWhat was created:", :yellow
  say "1. Model: app/models/#{model_name.underscore}.rb (with MultiTenant concern included)", :yellow
  say "2. Migration: #{migration_file_name}.rb (with RLS policies)", :yellow
  say '=' * 60, :green
end