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



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

def gem(gem_options)
  sentinel = 'Rails::Initializer.run do |config|'
  unless gsub_file_check 'config/environment.rb', /(#{Regexp.escape(gem_code(gem_options))})/mi
    logger.gem gem_code(gem_options)
    gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
        "#{m}\n  #{gem_code(gem_options)}"
    end
  else
    logger.identical gem_code(gem_options)
  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(route_options)
  sentinel = 'ActionController::Routing::Routes.draw do |map|'
  unless gsub_file_check 'config/routes.rb', /(#{Regexp.escape(route_code(route_options))})/mi
    logger.route route_code(route_options)
    gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m|
        "#{m}\n  #{route_code(route_options)}"
    end
  else
    logger.identical route_code(route_options)
  end
end