Sha256: bb833b2fea7d5365516042d19be878be35688b49744d7201b50961ecf82236c8

Contents?: true

Size: 1003 Bytes

Versions: 5

Compression:

Stored size: 1003 Bytes

Contents

require 'puppet/util'

module Puppet::Util::RubyGems

  #Base/factory class for rubygems source
  class Source
    class << self
      def has_rubygems?
        begin
          require 'rubygems'
          true
        rescue LoadError
          false
        end
      end

      def source
        if has_rubygems?
          Gem::Specification.respond_to?(:latest_specs) ? Gems18Source : OldGemsSource
        else
          NoGemsSource
        end
      end

      def new(*args)
        object = source.allocate
        object.send(:initialize, *args)
        object
      end
    end
  end

  # For RubyGems >= 1.8.0
  class Gems18Source < Source
    def directories
      Gem::Specification.latest_specs.collect do |spec|
        File.join(spec.full_gem_path, 'lib')
      end
    end
  end

  # RubyGems < 1.8.0
  class OldGemsSource < Source
    def directories
      @paths ||= Gem.latest_load_paths
    end
  end

  class NoGemsSource < Source
    def directories
      []
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppet-3.0.0 lib/puppet/util/rubygems.rb
puppet-3.0.0.rc8 lib/puppet/util/rubygems.rb
puppet-3.0.0.rc7 lib/puppet/util/rubygems.rb
puppet-3.0.0.rc5 lib/puppet/util/rubygems.rb
puppet-3.0.0.rc4 lib/puppet/util/rubygems.rb