Class: FlattenRecord::Generators::MigrationGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- FlattenRecord::Generators::MigrationGenerator
- Defined in:
- lib/generators/flatten_record/migration/migration_generator.rb
Overview
Migration generator that creates migration file from template
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.source_root ⇒ Object
7 8 9 |
# File 'lib/generators/flatten_record/migration/migration_generator.rb', line 7 def self.source_root @source_root ||= File.join(File.dirname(__FILE__), 'templates') end |
Instance Method Details
#generate_files ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/flatten_record/migration/migration_generator.rb', line 13 def generate_files if !valid? puts(red("Error. #{name.camelize} is not found")) and return end defined_classes.each do |class_name| @klass = class_name.constantize @table_name = @klass.table_name @table_columns = denormalized_columns if case when @klass.table_exists? puts yellow("Warning. Table already exists: #{@table_name}") diff_and_generate if when migration_template('migration.erb', "db/migrate/create_table_#{@table_name}.rb") else puts red("Error. No denormalization definition found in #{@table_name}") end end end |