Class: Rails::Generator::Commands::Create

Inherits:
Object
  • Object
show all
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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/generators/generator_extensions.rb', line 45

def gem(gem_options)
  sentinel = 'Rails::Initializer.run do |config|'
  if gsub_file_check 'config/environment.rb', /(#{Regexp.escape(gem_code(gem_options))})/mi
    logger.identical gem_code(gem_options)
  else
    logger.gem gem_code(gem_options)
    gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
      "#{m}\n  #{gem_code(gem_options)}"
    end
  end
end

#route(route_options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/generator_extensions.rb', line 33

def route(route_options)
  sentinel = 'ActionController::Routing::Routes.draw do |map|'
  if gsub_file_check 'config/routes.rb', /(#{Regexp.escape(route_code(route_options))})/mi
    logger.identical route_code(route_options)
  else
    logger.route route_code(route_options)
    gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
      "#{m}\n  #{route_code(route_options)}"
    end
  end
end