diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-27 09:25:25 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-27 09:25:25 +0000 |
commit | 868e6b08df4b16fb71cc8a66308174253ff67bdb (patch) | |
tree | 70e1a892af080abab1f69e0aa826c2e5c1faebae /railties/lib/rails_generator/lookup.rb | |
parent | 557e19346ad144deecd7d76a8a4e4cec22a6597e (diff) | |
download | rails-868e6b08df4b16fb71cc8a66308174253ff67bdb.tar.gz rails-868e6b08df4b16fb71cc8a66308174253ff67bdb.tar.bz2 rails-868e6b08df4b16fb71cc8a66308174253ff67bdb.zip |
Generators: look for generators in all gems, not just those suffixed with _generator, in the gem's generators or rails_generators directory. Allow use of the rails_generators directory instead of the standard generators directory in plugins also. Closes #8730.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7139 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/lookup.rb')
-rw-r--r-- | railties/lib/rails_generator/lookup.rb | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb index 9446353013..ca46afa418 100644 --- a/railties/lib/rails_generator/lookup.rb +++ b/railties/lib/rails_generator/lookup.rb @@ -46,7 +46,7 @@ module Rails # # A spec is not a generator: it's a description of where to find # the generator and how to create it. A source is anything that - # yields generators from #each. PathSource and GemSource are provided. + # yields generators from #each. PathSource and GemGeneratorSource are provided. module Lookup def self.included(base) base.extend(ClassMethods) @@ -101,9 +101,13 @@ module Rails 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") + sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/rails_generators") end sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") - sources << GemSource.new if Object.const_defined?(:Gem) + if Object.const_defined?(:Gem) + sources << GemGeneratorSource.new + sources << GemPathSource.new + end sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") end @@ -185,14 +189,15 @@ module Rails end end - - # GemSource hits the mines to quarry for generators. The latest versions - # of gems named *_generator are selected. - class GemSource < Source + class AbstractGemSource < Source def initialize super :RubyGems end + end + # GemGeneratorSource hits the mines to quarry for generators. The latest versions + # of gems named *_generator are selected. + class GemGeneratorSource < AbstractGemSource # Yield latest versions of generator gems. def each Gem::cache.search(/_generator$/).inject({}) { |latest, gem| @@ -205,5 +210,31 @@ module Rails end end + # GemPathSource looks for generators within any RubyGem's /rails_generators/<generator_name>_generator.rb file. + class GemPathSource < AbstractGemSource + # Yield each generator within rails_generator subdirectories. + def each + generator_full_paths.each do |generator| + yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label) + end + end + + private + def generator_full_paths + @generator_full_paths ||= + Gem::cache.inject({}) do |latest, name_gem| + name, gem = name_gem + hem = latest[gem.name] + latest[gem.name] = gem if hem.nil? or gem.version > hem.version + latest + end.values.inject([]) do |mem, gem| + Dir[gem.full_gem_path + '/{rails_,}generators/**/*_generator.rb'].each do |generator| + mem << generator + end + mem + end + end + end + end end |