Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't use globbing (find_in_source_path) but warn and load RubyGems i…

…nstead
  • Loading branch information...
commit 2004d595b4a7d4f19f46dfceef719e99091d8dea 1 parent 6c6c768
Fabien Franzen authored
Showing with 22 additions and 19 deletions.
  1. +9 −7 lib/minigems.rb
  2. +13 −12 spec/minigems_spec.rb
16 lib/minigems.rb
View
@@ -61,7 +61,7 @@ def require(path) # :nodoc:
if !path.include?('/') && (match = Gem.find_name(path))
Gem.activate_gem_from_path(match.first)
return gem_original_require(path)
- elsif (spec = (Gem.find_in_source_path(path) || Gem.find_in_source_index(path)))
+ elsif spec = Gem.searcher.find(path)
Gem.activate(spec.name, "= #{spec.version}")
return gem_original_require(path)
end
@@ -268,7 +268,7 @@ def self.find_in_source_path(path)
# Find a file in the Gem source index - loads up the full rubygems!
def self.find_in_source_index(path)
return nil if path == 'Win32API' && !Gem.win_platform?
- puts "Switching from minigems to full rubygems..." if $MINIGEMS_DEBUG
+ show_notification "Switching from minigems to full rubygems..."
Gem.searcher.find(path)
end
@@ -305,11 +305,9 @@ def self.report_activate_error(gem)
# Load the full rubygems suite, at which point all minigems logic
# is being overridden, so all regular methods and classes are available.
def self.load_full_rubygems!
- if $MINIGEMS_DEBUG
- puts 'Loaded full RubyGems'
- if !caller.first.to_s.match(/`const_missing'$/) && (require_entry = get_require_caller(caller))
- puts "A gem was possibly implicitly loaded from #{require_entry}"
- end
+ show_notification 'Loaded full RubyGems'
+ if !caller.first.to_s.match(/`const_missing'$/) && (require_entry = get_require_caller(caller))
+ show_notification "A gem was possibly implicitly loaded from #{require_entry}"
end
# Clear out any minigems methods
class << self
@@ -328,6 +326,10 @@ def self.get_require_caller(callstack)
entry
end
end
+
+ def self.show_notification(msg)
+ puts "\033[1;31m#{msg}\033[0m"
+ end
# Record all minigems methods - except the minigems? predicate method.
MINIGEMS_METHODS = Gem.methods(false) - ["minigems?"]
25 spec/minigems_spec.rb
View
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'minigems')
+# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+require 'minigems'
# We can't use the spec runner, as that will already load or full gems!
gem "rspec"
@@ -8,9 +9,9 @@
before do
# Setup rubygems from our spec fixtures directory
- Gem.refresh
@gem_dir = File.join(File.dirname(__FILE__), "fixtures")
Gem.path.replace([@gem_dir])
+ Gem.refresh
end
after do
@@ -93,16 +94,16 @@
AwesomeGem::VERSION.should == "0.0.2"
end
- it "for gems with a CamelCased package name" do
- require("camel_cased_gem").should be_true
- lambda { CamelCasedGem::Awesome }.should_not raise_error(NameError)
- CamelCasedGem::VERSION.should == "0.0.1"
- end
-
- it "for files in a gems' load path" do
- require("super_sonic").should be_true
- lambda { AwesomeGem::SuperSonic }.should_not raise_error(NameError)
- end
+ # it "for gems with a CamelCased package name" do
+ # require("camel_cased_gem").should be_true
+ # lambda { CamelCasedGem::Awesome }.should_not raise_error(NameError)
+ # CamelCasedGem::VERSION.should == "0.0.1"
+ # end
+ #
+ # it "for files in a gems' load path" do
+ # require("super_sonic").should be_true
+ # lambda { AwesomeGem::SuperSonic }.should_not raise_error(NameError)
+ # end
end
Please sign in to comment.
Something went wrong with that request. Please try again.