Class: LocalizableDb::Generators::MigrationGenerator
- Inherits:
-
ActiveRecord::Generators::MigrationGenerator
- Object
- ActiveRecord::Generators::MigrationGenerator
- LocalizableDb::Generators::MigrationGenerator
- Includes:
- OrmHelper
- Defined in:
- lib/generators/localizable_db/migration_generator.rb
Instance Method Summary collapse
Methods included from Languages
Instance Method Details
#create_migration_file ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/localizable_db/migration_generator.rb', line 17 def create_migration_file if !model_exists? and behavior == :invoke raise "Model #{table_name.singularize.camelize} doesn't exist," + " please run 'bundle exec rails g localizable_db:model #{table_name. singularize.camelize}' or create the model #{table_name .singularize.camelize} and run localizable_db:migration again." return end attributes.each { |a| a..delete(:index) if a.reference? && !a.has_index? } if [:indexes] == false template = "#{__FILE__}/../templates/migration_for.rb" migration_name = "db/migrate/create_#{table_name.singularize}_languages.rb" migration_template( template, migration_name, migration_version: migration_version ) end |
#generate_localizable_model ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/localizable_db/migration_generator.rb', line 38 def generate_localizable_model if !model_exists? and behavior == :invoke raise "Model #{table_name.singularize.camelize} doesn't exist" return end case behavior when :invoke inject_into_class( Rails.root.join("app", "models", "#{table_name.singularize}.rb"), Object.const_get(table_name.singularize.camelize) ) do %Q{\tlocalize\n} end when :revoke # Do nothing end end |