Class: Rails::Generator::Commands::Create
- Inherits:
-
Object
- Object
- Rails::Generator::Commands::Create
- Defined in:
- lib/generators/generator_extensions.rb
Overview
Here’s a readable version of the long string used above in route_code; but it should be kept on one line to avoid inserting extra whitespace into routes.rb when the generator is run: “map.#:name ‘#:name’,
:controller => '#{route_options[:controller]}',
:action => '#{route_options[:action]}'"
Instance Method Summary collapse
Instance Method Details
#gem(gem_options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/generator_extensions.rb', line 46 def gem() sentinel = 'Rails::Initializer.run do |config|' unless gsub_file_check 'config/environment.rb', /(#{Regexp.escape(gem_code())})/mi logger.gem gem_code() gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |m| "#{m}\n #{gem_code()}" end else logger.identical gem_code() end end |
#route(route_options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/generator_extensions.rb', line 34 def route() sentinel = 'ActionController::Routing::Routes.draw do |map|' unless gsub_file_check 'config/routes.rb', /(#{Regexp.escape(route_code())})/mi logger.route route_code() gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m| "#{m}\n #{route_code()}" end else logger.identical route_code() end end |