Sha256: 649ba07db5786eea8c75e90826f273d9b1772d4011981935e682ab747f0c8a0e

Contents?: true

Size: 1.43 KB

Versions: 22

Compression:

Stored size: 1.43 KB

Contents

module Bundler
  # Finder behaves like a rubygems source index in that it responds
  # to #search. It also resolves a list of dependencies finding the
  # best possible configuration of gems that satisifes all requirements
  # without causing any gem activation errors.
  class Finder

    # Takes an array of gem sources and fetches the full index of
    # gems from each one. It then combines the indexes together keeping
    # track of the original source so that any resolved gem can be
    # fetched from the correct source.
    #
    # ==== Parameters
    # *sources<String>:: URI pointing to the gem repository
    def initialize(*sources)
      @cache   = {}
      @index   = {}
      @sources = sources
    end

    # Searches for a gem that matches the dependency
    #
    # ==== Parameters
    # dependency<Gem::Dependency>:: The gem dependency to search for
    #
    # ==== Returns
    # [Gem::Specification]:: A collection of gem specifications
    #   matching the search
    def search(dependency)
      @cache[dependency.hash] ||= begin
        find_by_name(dependency.name).select do |spec|
          dependency =~ spec
        end.sort_by {|s| s.version }
      end
    end

  private

    def find_by_name(name)
      matches = @index[name] ||= begin
        versions = {}
        @sources.reverse_each do |source|
          versions.merge! source.specs[name] || {}
        end
        versions
      end
      matches.values
    end

  end
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
bowline-bundler-0.0.4 lib/bowline/bundler/finder.rb
bowline-bundler-0.0.3 lib/bowline/bundler/finder.rb
bowline-bundler-0.0.2 lib/bowline/bundler/finder.rb
bowline-bundler-0.0.1 lib/bowline/bundler/finder.rb
peritor-bundler-0.7.0 lib/bundler/finder.rb
bundler08-0.8.5 lib/bundler08/finder.rb
bundler08-0.8.4 lib/bundler08/finder.rb
bundler08-0.8.3 lib/bundler08/finder.rb
bundler08-0.8.2 lib/bundler08/finder.rb
moneypools-bundler-0.8.1 lib/bundler/finder.rb
bundler-0.8.1 lib/bundler/finder.rb
bundler-0.8.0 lib/bundler/finder.rb
bundler-0.7.3.pre2 lib/bundler/finder.rb
bundler-0.7.3.pre lib/bundler/finder.rb
bundler-0.7.2 lib/bundler/finder.rb
bundler-0.7.1 lib/bundler/finder.rb
moneypools-bundler-0.7.1.pre lib/bundler/finder.rb
bundler-0.7.0 lib/bundler/finder.rb
bundler-0.6.0 lib/bundler/finder.rb
bundler-0.5.0 lib/bundler/finder.rb