Skip to content

Instantly share code, notes, and snippets.

@koshigoe
Created February 18, 2011 18:50
Show Gist options
  • Save koshigoe/834190 to your computer and use it in GitHub Desktop.
Save koshigoe/834190 to your computer and use it in GitHub Desktop.
fixed a problem that choose wrong class if loaded nested class.
diff --git a/lib/guard.rb b/lib/guard.rb
index b5a6c04..f4f826d 100644
--- a/lib/guard.rb
+++ b/lib/guard.rb
@@ -82,11 +82,7 @@ module Guard
def get_guard_class(name)
require "guard/#{name.downcase}"
- klasses = []
- ObjectSpace.each_object(Class) do |klass|
- klasses << klass if klass.to_s.downcase.match(/^guard::#{name.downcase}/)
- end
- klasses.first
+ self.const_get(self.constants.find{|klass_name| klass_name.to_s.downcase == name.downcase })
rescue LoadError
UI.error "Could not find gem 'guard-#{name}', please add it in your Gemfile."
end
@@ -98,4 +94,4 @@ module Guard
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb
index 74b9653..499a740 100644
--- a/spec/guard_spec.rb
+++ b/spec/guard_spec.rb
@@ -28,6 +28,14 @@ describe Guard do
it "should return Guard::RSpec" do
Guard.get_guard_class('rspec').should == Guard::RSpec
end
+
+ context 'loaded some nested classes' do
+ it "should return Guard::RSpec" do
+ require 'guard/rspec'
+ Guard::RSpec.class_eval('class NotGuardClass; end')
+ Guard.get_guard_class('rspec').should == Guard::RSpec
+ end
+ end
end
describe ".locate_guard" do
@@ -82,4 +90,4 @@ describe Guard do
end
end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment