Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Roll our own Gem#latest_load_paths and use it when Bundler not active

  • Loading branch information...
commit 50c670dd46720efb0f6c477166f377f00b707f07 1 parent 27f07fb
Tim Harper timcharper authored
Showing with 36 additions and 1 deletion.
  1. +2 −1  lib/spork.rb
  2. +34 −0 lib/spork/gem_helpers.rb
3  lib/spork.rb
View
@@ -11,6 +11,7 @@ module Spork
autoload :Runner, (LIBDIR + 'spork/runner').to_s
autoload :Forker, (LIBDIR + 'spork/forker').to_s
autoload :Diagnoser, (LIBDIR + 'spork/diagnoser').to_s
+ autoload :GemHelpers, (LIBDIR + 'spork/gem_helpers').to_s
class << self
# Run a block, during prefork mode. By default, if prefork is called twice in the same file and line number, the supplied block will only be ran once.
@@ -104,7 +105,7 @@ def detect_and_require(subfolder)
# This method is used to auto-discover peer plugins such as spork-testunit.
def other_spork_gem_load_paths
- @other_spork_gem_load_paths ||= $LOAD_PATH.uniq.grep(/spork/).select do |g|
+ @other_spork_gem_load_paths ||= Spork::GemHelpers.latest_load_paths.grep(/spork/).select do |g|
not g.match(%r{/spork-[0-9\-.]+/lib}) # don't include other versions of spork
end
end
34 lib/spork/gem_helpers.rb
View
@@ -0,0 +1,34 @@
+module Spork::GemHelpers
+ extend self
+
+ class GemPath
+ attr_reader :name, :version, :path, :version_numbers
+ include Comparable
+ def initialize(p)
+ @path = p
+ @name, @version = File.basename(p).scan(/^(.+?)-([^-]+)$/).flatten
+ @version_numbers = @version.split(/[^0-9]+/).map(&:to_i)
+ end
+
+ def <=>(other)
+ raise "Not comparable gem paths ('#{name}' is not '#{other.name}')" unless name == other.name
+ @version_numbers <=> other.version_numbers
+ end
+ end
+
+ def latest_load_paths
+ if defined?(Bundler)
+ $LOAD_PATH.uniq
+ else
+ Dir["{#{Gem.paths.path.join(',')}}" + "/gems/*"].inject({}) do |h,f|
+ gem_path = GemPath.new(f)
+ if h[gem_path.name]
+ h[gem_path.name] = gem_path if gem_path > h[gem_path.name]
+ else
+ h[gem_path.name] = gem_path
+ end
+ h
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.