Class: Rails::Generator::Commands::Base
- Inherits:
-
Object
- Object
- Rails::Generator::Commands::Base
- Includes:
- RailsGeneratorExtensions
- Defined in:
- lib/generator_extensions.rb
Instance Method Summary collapse
- #add_to_file(file, sentinel, text) ⇒ Object
- #add_to_initializer(text) ⇒ Object
- #add_to_routes(text) ⇒ Object
Methods included from RailsGeneratorExtensions
Instance Method Details
#add_to_file(file, sentinel, text) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generator_extensions.rb', line 47 def add_to_file(file, sentinel, text) first_line = text.split("\n")[0] matched = /:in `([^']+)'$/.match(caller.first) logger.send(matched[1].to_sym, first_line) if matched unless [:pretend] gsub_file file, /(#{Regexp.escape(sentinel)})/mi do |match| "#{match}\n#{text}\n" end end end |
#add_to_initializer(text) ⇒ Object
41 42 43 44 45 |
# File 'lib/generator_extensions.rb', line 41 def add_to_initializer(text) add_to_file('config/environment.rb', 'Rails::Initializer.run do |config|', text) end |
#add_to_routes(text) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/generator_extensions.rb', line 34 def add_to_routes(text) add_to_file('config/routes.rb', 'ActionController::Routing::Routes.draw do |map|', text ) end |