Permalink
Browse files

Only require 'json' if it needs to be.

This works around an issue with using Gems like yajl-ruby that include
a compatibility API by preventing Faraday::Middleware.dependency from
overriding the compatibility shim.
  • Loading branch information...
1 parent 4784775 commit 4a4d6a00108b27dfc7ae4d8e5ffae1eff6e9eb07 @tylerhunt tylerhunt committed Mar 27, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/faraday_middleware/response/parse_json.rb
@@ -3,7 +3,9 @@
module FaradayMiddleware
# Public: Parse response bodies as JSON.
class ParseJson < ResponseMiddleware
- dependency 'json'
+ dependency {
+ require 'json' unless defined?(JSON)
+ }
define_parser { |body|
JSON.parse body unless body.empty?

0 comments on commit 4a4d6a0

Please sign in to comment.