Methods
A
I
L
P
R
S
U
Instance Public methods
append_sources(*args)

Add a source to the end of the list.

# File rails/railties/lib/rails_generator/lookup.rb, line 68
def append_sources(*args)
  sources.concat(args.flatten)
  invalidate_cache!
end
instance(generator_name, args = [], runtime_options = {})

Convenience method to lookup and instantiate a generator.

# File rails/railties/lib/rails_generator/lookup.rb, line 127
def instance(generator_name, args = [], runtime_options = {})
  lookup(generator_name).klass.new(args, full_options(runtime_options))
end
lookup(generator_name)

Lookup knows how to find generators' Specs from a list of Sources. Searches the sources, in order, for the first matching name.

# File rails/railties/lib/rails_generator/lookup.rb, line 112
def lookup(generator_name)
  @found ||= {}
  generator_name = generator_name.to_s.downcase
  @found[generator_name] ||= cache.find { |spec| spec.name == generator_name }
  unless @found[generator_name] 
    chars = generator_name.scan(%r./).map{|c|"#{c}.*?"}
    rx = %r^#{chars}$/
    gns = cache.select{|spec| spec.name =~ rx }
    @found[generator_name] ||= gns.first if gns.length == 1
    raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1
  end
  @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator"
end
prepend_sources(*args)

Add a source to the beginning of the list.

# File rails/railties/lib/rails_generator/lookup.rb, line 74
def prepend_sources(*args)
  write_inheritable_array(:sources, args.flatten + sources)
  invalidate_cache!
end
reset_sources()

Reset the source list.

# File rails/railties/lib/rails_generator/lookup.rb, line 80
def reset_sources
  write_inheritable_attribute(:sources, [])
  invalidate_cache!
end
sources()

The list of sources where we look, in order, for generators.

# File rails/railties/lib/rails_generator/lookup.rb, line 63
def sources
  read_inheritable_attribute(:sources) or use_component_sources!
end
use_application_sources!()

Use application generators (app, ?).

# File rails/railties/lib/rails_generator/lookup.rb, line 86
def use_application_sources!
  reset_sources
  sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/applications")
end
use_component_sources!()

Use component generators (model, controller, etc).

  1. Rails application. If RAILS_ROOT is defined we know we're generating in the context of a Rails application, so search RAILS_ROOT/generators.

  2. User home directory. Search ~/.rails/generators.

  3. RubyGems. Search for gems named *_generator.

  4. Builtins. Model, controller, mailer, scaffold.

# File rails/railties/lib/rails_generator/lookup.rb, line 98
def use_component_sources!
  reset_sources
  if defined? ::RAILS_ROOT
    sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators")
    sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
    sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/**/generators")
  end
  sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
  sources << GemSource.new if Object.const_defined?(:Gem)
  sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components")
end