Browse files

Fix Issue #1: default_engine check for json gem fails.

Instead of trying to mangle the required library name to get the symbol,
map the libraries to their symbols, this way it'll also be much more
extensible in the future.
  • Loading branch information...
1 parent f59cf41 commit caced0c4e8c795922a109ebc00c3c4fa8635bed8 @Flameeyes Flameeyes committed Jun 19, 2010
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/multi_json.rb
View
15 lib/multi_json.rb
@@ -7,6 +7,13 @@ def engine
self.engine = self.default_engine
@engine
end
+
+ DefaultByRequire = {
+ "yajl" => :yajl,
+ "json" => :json_gem,
+ "active_support" => :active_support,
+ "json/pure" => :json_pure
+ }
# The default engine based on what you currently
# have loaded and installed. First checks to see
@@ -16,11 +23,11 @@ def default_engine
return :yajl if defined?(::Yajl)
return :json_gem if defined?(::JSON)
return :active_support if defined?(::ActiveSupport::JSON)
-
- %w(yajl json active_support json/pure).each do |req|
+
+ DefaultByRequire.each_pair do |library, engine|
begin
- require req
- return req.sub('/','_').to_sym
+ require library
+ return engine
rescue LoadError
next
end

0 comments on commit caced0c

Please sign in to comment.