Methods
F
H
I
N
S
T
Classes and Modules
Constants
RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
 

We need to store the RAILS_DEV_PATH in a constant, otherwise the path can change in Ruby 1.8.7 when we FileUtils.cd.

RESERVED_NAMES = %w[application destroy benchmarker profiler plugin runner test]
DEFAULT_ALIASES = { :rails => { :actions => '-a', :orm => '-o', :javascripts => '-j', :javascript_engine => '-je', :resource_controller => '-c', :scaffold_controller => '-c', :stylesheets => '-y', :stylesheet_engine => '-se', :template_engine => '-e', :test_framework => '-t' }, :test_unit => { :fixture_replacement => '-r', }, :plugin => { :generator => '-g', :tasks => '-r' } }
DEFAULT_OPTIONS = { :rails => { :assets => true, :force_plural => false, :helper => true, :integration_tool => nil, :javascripts => true, :javascript_engine => :js, :orm => false, :performance_tool => nil, :resource_controller => :controller, :resource_route => true, :scaffold_controller => :scaffold_controller, :stylesheets => true, :stylesheet_engine => :css, :test_framework => false, :template_engine => :erb }, :plugin => { :generator => false, :tasks => false } }
Class Public methods
fallbacks()

Hold configured generators fallbacks. If a plugin developer wants a generator group to fallback to another group in case of missing generators, they can add a fallback.

For example, shoulda is considered a test_framework and is an extension of test_unit. However, most part of shoulda generators are similar to test_unit ones.

Shoulda then can tell generators to search for test_unit generators when some of them are not available by adding a fallback:

  Rails::Generators.fallbacks[:shoulda] = :test_unit
     # File railties/lib/rails/generators.rb, line 109
109:     def self.fallbacks
110:       @fallbacks ||= {}
111:     end
help(command = 'generate')

Show help message with available generators.

     # File railties/lib/rails/generators.rb, line 220
220:     def self.help(command = 'generate')
221:       lookup!
222: 
223:       namespaces = subclasses.map{ |k| k.namespace }
224:       namespaces.sort!
225: 
226:       groups = Hash.new { |h,k| h[k] = [] }
227:       namespaces.each do |namespace|
228:         base = namespace.split(':').first
229:         groups[base] << namespace
230:       end
231: 
232:       puts "Usage: rails #{command} GENERATOR [args] [options]"
233:       puts
234:       puts "General options:"
235:       puts "  -h, [--help]     # Print generator's options and usage"
236:       puts "  -p, [--pretend]  # Run but do not make any changes"
237:       puts "  -f, [--force]    # Overwrite files that already exist"
238:       puts "  -s, [--skip]     # Skip files that already exist"
239:       puts "  -q, [--quiet]    # Suppress status output"
240:       puts
241:       puts "Please choose a generator below."
242:       puts
243: 
244:       # Print Rails defaults first.
245:       rails = groups.delete("rails")
246:       rails.map! { |n| n.sub(/^rails:/, '') }
247:       rails.delete("app")
248:       rails.delete("plugin_new")
249:       print_list("rails", rails)
250: 
251:       hidden_namespaces.each {|n| groups.delete(n.to_s) }
252: 
253:       groups.sort.each { |b, n| print_list(b, n) }
254:     end
hidden_namespaces()
     # File railties/lib/rails/generators.rb, line 177
177:     def self.hidden_namespaces
178:       @hidden_namespaces ||= begin
179:         orm      = options[:rails][:orm]
180:         test     = options[:rails][:test_framework]
181:         template = options[:rails][:template_engine]
182:         css      = options[:rails][:stylesheet_engine]
183: 
184:         [
185:           "rails",
186:           "resource_route",
187:           "#{orm}:migration",
188:           "#{orm}:model",
189:           "#{orm}:observer",
190:           "#{orm}:session_migration",
191:           "#{test}:controller",
192:           "#{test}:helper",
193:           "#{test}:integration",
194:           "#{test}:mailer",
195:           "#{test}:model",
196:           "#{test}:observer",
197:           "#{test}:scaffold",
198:           "#{test}:view",
199:           "#{test}:performance",
200:           "#{test}:plugin",
201:           "#{template}:controller",
202:           "#{template}:scaffold",
203:           "#{template}:mailer",
204:           "#{css}:scaffold",
205:           "#{css}:assets",
206:           "css:assets",
207:           "css:scaffold"
208:         ]
209:       end
210:     end
hide_namespaces(*namespaces)
     # File railties/lib/rails/generators.rb, line 213
213:       def hide_namespaces(*namespaces)
214:         hidden_namespaces.concat(namespaces)
215:       end
invoke(namespace, args=ARGV, config={})

Receives a namespace, arguments and the behavior to invoke the generator. It’s used as the default entry point for generate, destroy and update commands.

     # File railties/lib/rails/generators.rb, line 167
167:     def self.invoke(namespace, args=ARGV, config={})
168:       names = namespace.to_s.split(':')
169:       if klass = find_by_namespace(names.pop, names.any? && names.join(':'))
170:         args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
171:         klass.start(args, config)
172:       else
173:         puts "Could not find generator #{namespace}."
174:       end
175:     end
no_color!()

Remove the color from output.

     # File railties/lib/rails/generators.rb, line 114
114:     def self.no_color!
115:       Thor::Base.shell = Thor::Shell::Basic
116:     end
subclasses()

Track all generators subclasses.

     # File railties/lib/rails/generators.rb, line 119
119:     def self.subclasses
120:       @subclasses ||= []
121:     end
templates_path()
    # File railties/lib/rails/generators.rb, line 84
84:     def self.templates_path
85:       @templates_path ||= []
86:     end