Class: ModelMill::Generators::ModelsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/model_mill/models/models_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_modelsObject

argument :excludes, :type => :array, :required => false, :default => []



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/model_mill/models/models_generator.rb', line 9

def generate_models
  if options[:namespace]
    empty_directory("app/models/#{options[:namespace].downcase}")
    generate_base_namespaced_model
  end
  discovered_tables.each do |table_name|
    @model_name = model_name_from_table_name table_name
    @model_file_name = model_file_name_from_table_name table_name
    @columns = connection.columns(table_name)
    @indexes = connection.indexes(table_name)
    @associations = detected_associations(table_name, @columns)
    template 'model.rb', "app/models/#{options[:namespace] ? options[:namespace]+'/' : ''}#{@model_file_name}.rb"
  end
  puts %Q(config.autoload_paths += %W(\#{config.root}/app/models/#{options[:namespace].downcase})) if options[:namespace]
end