Class: MegaBar::MegaBarGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MegaBar::MegaBarGenerator
- Defined in:
- lib/generators/mega_bar/mega_bar/mega_bar_generator.rb
Instance Method Summary collapse
-
#create_controller_file ⇒ Object
in generators, all public methods are run.
- #create_model_file ⇒ Object
- #generate_migration ⇒ Object
- #route ⇒ Object
Instance Method Details
#create_controller_file ⇒ Object
in generators, all public methods are run. Weird, huh?
9 10 11 12 13 14 15 |
# File 'lib/generators/mega_bar/mega_bar/mega_bar_generator.rb', line 9 def create_controller_file template "generic_controller.rb", "#{the_controller_file_name}.rb" if the_module_name # template "generic_controller.rb", "tmp_#{the_controller_file_name}.rb" end end |
#create_model_file ⇒ Object
16 17 18 19 20 21 |
# File 'lib/generators/mega_bar/mega_bar/mega_bar_generator.rb', line 16 def create_model_file template "generic_model.rb", "#{the_model_file_name}" if the_module_name # template "generic_model.rb", "Tmp#{the_model_file_name}.rb" end end |
#generate_migration ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/mega_bar/mega_bar/mega_bar_generator.rb', line 22 def generate_migration if the_module_name generate 'migration create_' + the_module_name + '_' + the_table_name + ' created_at:datetime updated_at:datetime' # generate 'migration create_tmp_' + the_module_name + '_' + the_table_name + ' created_at:datetime updated_at:datetime' else generate 'migration create_' + the_table_name + ' created_at:datetime updated_at:datetime' end end |
#route ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/generators/mega_bar/mega_bar/mega_bar_generator.rb', line 31 def route line = ' ##### MEGABAR END' text = File.read('config/routes.rb') new_contents = text.gsub( /(#{Regexp.escape(line)})/mi, 'resource :' + the_route_name + "\n #{line}\n") # To write changes to the file, use: File.open('config/routes.rb', "w") {|file| file.puts new_contents } end |