[Rubygems-developers] methdos for active?, gemspec and location

TRANS transfire at gmail.com
Mon Apr 16 13:21:38 EDT 2007


Does RubyGems have means for determining if a gem is active or not?
And a way to get it's gemspec and locating it's files? I had written
these extensions for doing so sometime ago. Hopefully there are
built-in ways for accessing such information and these aren't of use
anymore. Otherwise perhaps they could be used to provide that access.

 module Gem

  # Is a gem active?
  def self.active?(gemname)
    @loaded_specs ||= Hash.new
    @loaded_specs.key? gemname
  end

  # path to active gem's files
  def self.gempath(gemname, subdir=nil)
    if active?(gemname)
      if subdir
        File.join( @loaded_specs[gemname].full_gem_path, subdir )
      else
        @loaded_specs[gemname].full_gem_path
      end
    end
  end

  # an active gems gemspec
  def self.gemspec(gemname)
    @loaded_specs[gemname] if active?(gemname)
  end

 end


More information about the Rubygems-developers mailing list