Class: Rails::Generator::GemSource

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

Overview

GemSource 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 Source

#names

Constructor Details

#initializeGemSource

Returns a new instance of GemSource.



192
193
194
# File 'lib/rails_generator/lookup.rb', line 192

def initialize
  super :RubyGems
end

Instance Method Details

#eachObject

Yield latest versions of generator gems.



197
198
199
200
201
202
203
204
205
206
# File 'lib/rails_generator/lookup.rb', line 197

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