Class: Trimodel::NewGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Trimodel::NewGenerator
- Defined in:
- lib/generators/trimodel/new_generator.rb
Instance Method Summary collapse
- #check_parameters ⇒ Object
- #create_migration_files ⇒ Object
- #create_trimodel_file ⇒ Object
- #perform_migrations ⇒ Object
Instance Method Details
#check_parameters ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/generators/trimodel/new_generator.rb', line 12 def check_parameters if [:models].class == NilClass puts "error: You need to give the models you want to associate" puts "e.g. rails g trimodel:new --models a b c" elsif [:models].size != 3 puts "error: Wrong number of models, they should be 3" end end |
#create_migration_files ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/trimodel/new_generator.rb', line 21 def create_migration_files create_migration_file [:models][0], [:models][1] #need to wait so the timestamp has a different value #and forms a correct migration file name sleep(1) create_migration_file [:models][1], [:models][2] end |
#create_trimodel_file ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/generators/trimodel/new_generator.rb', line 33 def create_trimodel_file File.open(Rails.root + "config/initializers/trimodel.rb", File::CREAT|File::RDWR) do |f| add_one_asoc_to_model f, [:models][0], [:models][1], [:models][2] add_two_asocs_to_model f, [:models][1], [:models][0], [:models][2] add_one_asoc_to_model f, [:models][2], [:models][1], [:models][0] end end |
#perform_migrations ⇒ Object
29 30 31 |
# File 'lib/generators/trimodel/new_generator.rb', line 29 def perform_migrations %x[rake db:migrate] end |