Created
October 28, 2011 19:24
-
-
Save benolee/1323225 to your computer and use it in GitHub Desktop.
CamelCase guard name to find guard class name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/guard.rb b/lib/guard.rb | |
index 368d5aa..2795dc4 100644 | |
--- a/lib/guard.rb | |
+++ b/lib/guard.rb | |
@@ -398,10 +398,10 @@ module Guard | |
def get_guard_class(name) | |
name = name.to_s | |
try_require = false | |
- const_name = name.downcase.gsub('-', '') | |
+ const_name = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } | |
begin | |
require "guard/#{ name.downcase }" if try_require | |
- self.const_get(self.constants.find { |c| c.to_s.downcase == const_name }) | |
+ self.const_get(self.constants.find { |c| c.to_s == const_name }) | |
rescue TypeError | |
unless try_require | |
try_require = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment