diff --git a/bin/minigem b/bin/minigem index 1877e55..4549c10 100644 --- a/bin/minigem +++ b/bin/minigem @@ -72,7 +72,7 @@ elsif ARGV[0] == 'revert' elsif ARGV[0] == 'install' || ARGV[0] == 'update' # Install or update a rubygem and prepare it for minigems. command = ARGV.shift.to_sym # skip command argument - ensure_in_load_path! + ensure_in_load_path!(ARGV.empty?) # Remove any gems that have been specified. unless ARGV.empty? cmd = Gem::GemRunner.new.run_command(command, ARGV) diff --git a/lib/minigems.rb b/lib/minigems.rb index b59ad4e..33110a3 100644 --- a/lib/minigems.rb +++ b/lib/minigems.rb @@ -114,20 +114,18 @@ def self.activate(gem, *version_requirements) elsif already_loaded return false end - + # Keep track of loaded gems - by name instead of full specs (memory!) self.loaded_gems[gem_spec.name] = gem_spec.full_name # Load dependent gems first gem_spec.runtime_dependencies.each { |dep_gem| activate(dep_gem) } - - # Add gem bindir path to $LOAD_PATH - unless gem_spec.executables.empty? - $LOAD_PATH.unshift File.join(gem_spec.full_gem_path, gem_spec.bindir) - end + + # bin directory must come before library directories + gem_spec.require_paths.unshift(gem_spec.bindir) if gem_spec.bindir # Add gem require paths to $LOAD_PATH - gem_spec.require_paths.each do |require_path| + gem_spec.require_paths.reverse.each do |require_path| $LOAD_PATH.unshift File.join(gem_spec.full_gem_path, require_path) end return true diff --git a/spec/minigems_spec.rb b/spec/minigems_spec.rb index 4747fa0..abf6e65 100644 --- a/spec/minigems_spec.rb +++ b/spec/minigems_spec.rb @@ -51,24 +51,28 @@ gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin") $LOAD_PATH.should_not include(gem_lib_path) gem("gem_with_lib").should be_true - $LOAD_PATH.first.should == gem_lib_path - $LOAD_PATH.should include(gem_bin_path) + $LOAD_PATH.first.should == gem_bin_path + $LOAD_PATH.should include(gem_lib_path) $LOAD_PATH.select { |path| path == gem_lib_path }.length.should == 1 lambda { GemWithLib::Awesome }.should raise_error(NameError) end it "uses 'gem' to setup additional load path entries (for a specific gem version)" do gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.1", "lib") + gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.1", "bin") $LOAD_PATH.should_not include(gem_lib_path) gem("gem_with_lib", "0.0.1").should be_true - $LOAD_PATH.first.should == gem_lib_path + $LOAD_PATH.first.should == gem_bin_path + $LOAD_PATH.should include(gem_lib_path) end it "uses 'gem' to setup additional load path entries (for a gem version requirement)" do gem_lib_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "lib") + gem_bin_path = File.join(@gem_dir, "gems", "gem_with_lib-0.0.2", "bin") $LOAD_PATH.should_not include(gem_lib_path) gem("gem_with_lib", ">0.0.1").should be_true - $LOAD_PATH.first.should == gem_lib_path + $LOAD_PATH.first.should == gem_bin_path + $LOAD_PATH.should include(gem_lib_path) end it "correctly requires a file from the load path" do