Class: Rails::Generator::GemGeneratorSource

Inherits:
AbstractGemSource show all
Defined in:
lib/rails_generator/lookup.rb

Overview

GemGeneratorSource hits the mines to quarry for generators. The latest versions of gems named *_generator are selected.

Instance Attribute Summary

Attributes inherited from Source

#label

Instance Method Summary collapse

Methods inherited from AbstractGemSource

#initialize

Methods inherited from Source

#initialize, #names

Constructor Details

This class inherits a constructor from Rails::Generator::AbstractGemSource

Instance Method Details

#eachObject

Yield latest versions of generator gems.



210
211
212
213
214
215
216
217
218
219
# File 'lib/rails_generator/lookup.rb', line 210

def each
  dependency = Gem::Dependency.new(/_generator$/, Gem::Requirement.default)
  Gem::cache.search(dependency).inject({}) { |latest, gem|
    hem = latest[gem.name]
    latest[gem.name] = gem if hem.nil? or gem.version > hem.version
    latest
  }.values.each { |gem|
    yield Spec.new(gem.name.sub(/_generator$/, ''), gem.full_gem_path, label)
  }
end