Skip to content

Commit

Permalink
Use Object#respond_to? to determine which MultiJson API to use
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 19, 2012
1 parent e01bf0a commit 5e62670
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions activesupport/lib/active_support/json/decoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ module ActiveSupport
module JSON
class << self
def decode(json, options ={})
data = MultiJson.decode(json, options)
# Can't reliably detect whether MultiJson responds to load, since it's
# a reserved word. Use adapter as a proxy for new features.
data = if MultiJson.respond_to?(:adapter)
MultiJson.load(json, options)
else
MultiJson.decode(json, options)
end
if ActiveSupport.parse_json_times
convert_dates_from(data)
else
Expand All @@ -18,12 +24,20 @@ def decode(json, options ={})
end

def engine
MultiJson.engine
if MultiJson.respond_to?(:adapter)
MultiJson.adapter
else
MultiJson.engine
end
end
alias :backend :engine

def engine=(name)
MultiJson.engine = name
if MultiJson.respond_to?(:use)
MultiJson.use name
else
MultiJson.engine = name
end
end
alias :backend= :engine=

Expand Down

0 comments on commit 5e62670

Please sign in to comment.