Sha256: 09fda84cef91894b9bac7fd532aaf9db31ff091429b612f80a56f9ff1cd4122f
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
require File.dirname(__FILE__) + '/../../lib/legacy_data' # require File.dirname(__FILE__) + '/../../lib/legacy_data/table_definition' # require File.dirname(__FILE__) + '/../../lib/legacy_data/schema' # require File.dirname(__FILE__) + '/../../lib/legacy_data/table_class_name_mapper' # require File.dirname(__FILE__) + '/../../lib/active_record/connection_adapters/oracle_enhanced_adapter' class ModelsFromTablesGenerator < Rails::Generator::Base def manifest record do |m| m.directory File.join('app/models') LegacyData::TableClassNameMapper.naming_convention = options[:table_naming_convention] analyzed_tables = LegacyData::Schema.analyze(options) 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] m.template 'model.rb', File.join('app/models', "#{analyzed_table[:class_name].underscore}.rb"), :assigns => analyzed_table.to_hash end end # rescue => e # puts e.backtrace end protected def add_options!(opt) opt.on('--table-name [ARG]', 'Only generate models for given table') { |value| options[:table_name] = value } opt.on('--table-naming-convention [ARG]', 'Naming convention for tables in the database - will not be used when generating naming the models') { |value| options[:table_naming_convention] = value } opt.on('--skip-associated', 'Do not follow foreign keys to model associated tables') { |value| options[:skip_associated] = true } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
legacy_data-0.1.1 | generators/models_from_tables/models_from_tables_generator.rb |