Class Gem::SourceIndex
In: sprout/lib/sprout/generator/base_mixins.rb
Parent: Object

Methods

Public Instance methods

This feature seems to be getting deprecated from the latest gems releases (1.3.x). We actually need it and don‘t want the nagging - so, copied sources from RubyGems SVN trunk, and mixing in… :-( There should be a more stable integration point with RubyGems Any ideas or contributions are welcome!

[Source]

# File sprout/lib/sprout/generator/base_mixins.rb, line 11
  def sprout_search(gem_pattern, platform_only = false)
    version_requirement = nil
    only_platform = false

    # unless Gem::Dependency === gem_pattern
    #   warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
    # end

    case gem_pattern
    when Regexp then
      version_requirement = platform_only || Gem::Requirement.default
    when Gem::Dependency then
      only_platform = platform_only
      version_requirement = gem_pattern.version_requirements
      gem_pattern = if Regexp === gem_pattern.name then
                      gem_pattern.name
                    elsif gem_pattern.name.empty? then
                      //
                    else
                      /^#{Regexp.escape gem_pattern.name}$/
                    end
    else
      version_requirement = platform_only || Gem::Requirement.default
      gem_pattern = /#{gem_pattern}/i
    end

    unless Gem::Requirement === version_requirement then
      version_requirement = Gem::Requirement.create version_requirement
    end

    specs = @gems.values.select do |spec|
      spec.name =~ gem_pattern and
        version_requirement.satisfied_by? spec.version
    end

    if only_platform then
      specs = specs.select do |spec|
        Gem::Platform.match spec.platform
      end
    end
    
    begin
      specs.sort_by { |s| s.sort_obj }
    rescue NoMethodError => e
      puts "It looks like your RubyGems installation is not compatible with this version of Sprouts.\n\nTo update, run:\ngem update --system\n\n"
      raise e
    end
  end

[Validate]