Module: Root::Gems
- Defined in:
- lib/root/gems.rb
Overview
Methods for working with RubyGems.
Class Method Summary collapse
-
.gemspec(gem_name) ⇒ Object
Returns the gemspec for the specified gem.
-
.select_gems(latest = true) ⇒ Object
Selects gem specs for which the block returns true.
Class Method Details
.gemspec(gem_name) ⇒ Object
Returns the gemspec for the specified gem. A gem version can be specified in the name, like ‘gem >= 1.2’. The gem will be activated using gem if necessary.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/root/gems.rb', line 12 def gemspec(gem_name) return gem_name if gem_name.kind_of?(Gem::Specification) # figure the version of the gem, by default >= 0.0.0 gem_name.to_s =~ /^([^<=>]*)(.*)$/ name, version = $1.strip, $2 version = ">= 0.0.0" if version.empty? return nil if name.empty? # load the gem and get the spec gem(name, version) Gem.loaded_specs[name] end |
.select_gems(latest = true) ⇒ Object
Selects gem specs for which the block returns true. If latest is specified, only the latest version of each gem will be passed to the block.
30 31 32 33 34 35 36 37 38 |
# File 'lib/root/gems.rb', line 30 def select_gems(latest=true) index = latest ? Gem.source_index.latest_specs : Gem.source_index.gems.collect {|(name, spec)| spec } index.select do |spec| yield(spec) end.sort end |