Class: UnderConstruction::Generators::ConfigGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- UnderConstruction::Generators::ConfigGenerator
- Defined in:
- lib/generators/under_construction/config_generator.rb
Instance Method Summary collapse
- #config_route_file ⇒ Object
- #copy_config_file ⇒ Object
- #copy_index_file_to_app ⇒ Object
- #copy_scheduler_initializer ⇒ Object
- #edit_application_Controller ⇒ Object
Instance Method Details
#config_route_file ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/under_construction/config_generator.rb', line 21 def config_route_file file_path = 'config/routes.rb' if ::Rails::VERSION::MAJOR >= 4 gsub_file file_path, /#{Regexp.escape(ROUTES_CLEAR_TXT)}/, '' insert_into_file file_path, ROUTES_CONFIG_TXT, after: /Rails.application.routes.draw do/ gsub_file file_path, /(Rails.application.routes.draw do)(.*)(end)/m, '\1\2'+"#{ROUTES_REDIRECT_TO_TXT}" + '\3' else gsub_file file_path, /#{Regexp.escape(ROUTES_CLEAR_TXT)}/, '' insert_into_file file_path, ROUTES_CONFIG_TXT, after: /Application.routes.draw do/ gsub_file file_path, /(Application.routes.draw do)(.*)(end)/m, '\1\2'+"#{ROUTES_REDIRECT_TO_TXT}" + '\3' end end |
#copy_config_file ⇒ Object
17 18 19 |
# File 'lib/generators/under_construction/config_generator.rb', line 17 def copy_config_file copy_file 'under_construction.yml', 'config/under_construction.yml' end |
#copy_index_file_to_app ⇒ Object
34 35 36 |
# File 'lib/generators/under_construction/config_generator.rb', line 34 def copy_index_file_to_app directory 'under_construction', 'app/views/under_construction' end |
#copy_scheduler_initializer ⇒ Object
38 39 40 41 |
# File 'lib/generators/under_construction/config_generator.rb', line 38 def copy_scheduler_initializer destination_path = 'config/initializers/under_construction_scheduler.rb' copy_file 'under_construction_scheduler.rb', destination_path end |
#edit_application_Controller ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/generators/under_construction/config_generator.rb', line 9 def edit_application_Controller if File.exist?(Rails.root + "app/controllers/application_controller.rb") insert_into_file "app/controllers/application_controller.rb", APPLICATION_CONFIG_TXT, :after => "protect_from_forgery" else raise 'Couldn\'t find application_controller file' end end |