Class: ModelsFromTablesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/models_from_tables/models_from_tables_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_models_from_tablesObject

check_class_collision #:suffix => “ControllerTest”



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/models_from_tables/models_from_tables_generator.rb', line 15

def generate_models_from_tables
  LegacyData::TableClassNameMapper.naming_convention = options[:table_naming_convention]
  
  analyzed_tables = LegacyData::Schema.analyze(:table_name=>table_name, :skip_associated=>options[:skip_associated])

  unless analyzed_tables.blank?
    spec_dir_exists = File.exist? "#{Rails.root}/spec"

    LegacyData::TableClassNameMapper.let_user_validate_dictionary

    analyzed_tables.each do |analyzed_table|
      analyzed_table.class_name = LegacyData::TableClassNameMapper.class_name_for(analyzed_table[:table_name])

      # m.class_collisions :class_path, analyzed_table[:class_name]
      @definition = analyzed_table
      template 'model.rb', File.join('app/models', "#{analyzed_table[:class_name].underscore}.rb")

      add_factory_girl_factory analyzed_table if options[:with_factories] && spec_dir_exists
    end
  end
end