Sha256: 1f0199ed8478576118aff7abca7b04e7d2c0e7e952bcd36d4ee641887e1c06fd

Contents?: true

Size: 1.55 KB

Versions: 24

Compression:

Stored size: 1.55 KB

Contents

# encoding: utf-8

# This was added via Merb's bundler

require "rubygems"
require "rubygems/source_index"

module Gem
  BUNDLED_SPECS = File.join(Dir.pwd, "gems", "specifications")
  MAIN_INDEX = Gem::SourceIndex.from_gems_in(BUNDLED_SPECS)
  FALLBACK_INDEX = Gem::SourceIndex.from_installed_gems

  def self.source_index
    MultiSourceIndex.new
  end

  def self.searcher
    MultiPathSearcher.new
  end

  class ArbitrarySearcher < GemPathSearcher
    def initialize(source_index)
      @source_index = source_index
      super()
    end

    def init_gemspecs
      @source_index.map { |_, spec| spec }.sort { |a,b|
        (a.name <=> b.name).nonzero? || (b.version <=> a.version)
      }
    end
  end

  class MultiPathSearcher
    def initialize
      @main_searcher = ArbitrarySearcher.new(MAIN_INDEX)
      @fallback_searcher = ArbitrarySearcher.new(FALLBACK_INDEX)
    end

    def find(path)
      try = @main_searcher.find(path)
      return try if try
      @fallback_searcher.find(path)
    end

    def find_all(path)
      try = @main_searcher.find_all(path)
      return try unless try.empty?
      @fallback_searcher.find_all(path)
    end
  end

  class MultiSourceIndex
    # Used by merb.thor to confirm; not needed when MSI is in use
    def load_gems_in(*args)
    end

    def search(*args)
      try = MAIN_INDEX.search(*args)
      return try unless try.empty?
      FALLBACK_INDEX.search(*args)
    end

    def find_name(*args)
      try = MAIN_INDEX.find_name(*args)
      return try unless try.empty?
      FALLBACK_INDEX.find_name(*args)
    end
  end
end

Version data entries

24 entries across 6 versions & 1 rubygems

Version Path
rango-0.2.3 benchmarks/stubs/merb-app/tasks/merb.thor/common.rb
rango-0.2.3 benchmarks/stubs/merb-very-flat/tasks/merb.thor/common.rb
rango-0.2.3 benchmarks/stubs/merb-flat/tasks/merb.thor/common.rb
rango-0.2.3 benchmarks/stubs/merb-core/tasks/merb.thor/common.rb
rango-0.2.1 benchmarks/stubs/merb-flat/tasks/merb.thor/common.rb
rango-0.2.1 benchmarks/stubs/merb-core/tasks/merb.thor/common.rb
rango-0.2.1 benchmarks/stubs/merb-very-flat/tasks/merb.thor/common.rb
rango-0.2.1 benchmarks/stubs/merb-app/tasks/merb.thor/common.rb
rango-0.2.1.pre benchmarks/stubs/merb-app/tasks/merb.thor/common.rb
rango-0.2.1.pre benchmarks/stubs/merb-very-flat/tasks/merb.thor/common.rb
rango-0.2.1.pre benchmarks/stubs/merb-flat/tasks/merb.thor/common.rb
rango-0.2.1.pre benchmarks/stubs/merb-core/tasks/merb.thor/common.rb
rango-0.0.6 benchmarks/stubs/merb-very-flat/tasks/merb.thor/common.rb
rango-0.0.6 benchmarks/stubs/merb-app/tasks/merb.thor/common.rb
rango-0.0.6 benchmarks/stubs/merb-core/tasks/merb.thor/common.rb
rango-0.0.6 benchmarks/stubs/merb-flat/tasks/merb.thor/common.rb
rango-0.1.pre benchmarks/stubs/merb-core/tasks/merb.thor/common.rb
rango-0.1.pre benchmarks/stubs/merb-app/tasks/merb.thor/common.rb
rango-0.1.pre benchmarks/stubs/merb-flat/tasks/merb.thor/common.rb
rango-0.1.pre benchmarks/stubs/merb-very-flat/tasks/merb.thor/common.rb