instiki/vendor/rails/activesupport/lib/active_support/json/backends/jsongem.rb
Jacques Distler e3832c6f79 Rails 2.3.5
Upgrade to Rails 2.3.5.
Also work around this bug:
 https://rails.lighthouseapp.com/projects/8994/tickets/3524
created by the aforementioned
Rails release.
2009-11-30 19:38:34 -06:00

38 lines
851 B
Ruby

require 'json' unless defined?(JSON)
module ActiveSupport
module JSON
module Backends
module JSONGem
ParseError = ::JSON::ParserError
extend self
# Converts a JSON string into a Ruby object.
def decode(json)
data = ::JSON.parse(json)
if ActiveSupport.parse_json_times
convert_dates_from(data)
else
data
end
end
private
def convert_dates_from(data)
case data
when DATE_REGEX
DateTime.parse(data)
when Array
data.map! { |d| convert_dates_from(d) }
when Hash
data.each do |key, value|
data[key] = convert_dates_from(value)
end
else data
end
end
end
end
end
end