diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-04-23 14:34:37 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-04-23 14:34:37 +0100 |
commit | ae812c0a7bdb876c03752adfaa980ac4e74f2e17 (patch) | |
tree | 73eba5b0ddce60a4578fcbf6be581b8f35488273 /activesupport/lib/active_support/json.rb | |
parent | 67f30fd9639409877a57a7ba758cd13496433d69 (diff) | |
parent | 3c4c6bd0df598f865f49a983b4c65c415af4bcfc (diff) | |
download | rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.gz rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.tar.bz2 rails-ae812c0a7bdb876c03752adfaa980ac4e74f2e17.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport/lib/active_support/json.rb')
-rw-r--r-- | activesupport/lib/active_support/json.rb | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json.rb b/activesupport/lib/active_support/json.rb index 91f19f8a70..fc433de582 100644 --- a/activesupport/lib/active_support/json.rb +++ b/activesupport/lib/active_support/json.rb @@ -1,8 +1,37 @@ +require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/module/attribute_accessors' module ActiveSupport # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format. mattr_accessor :use_standard_json_time_format + # Look for and parse json strings that look like ISO 8601 times. + mattr_accessor :parse_json_times + + module JSON + # matches YAML-formatted dates + DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/ + + class << self + attr_reader :backend + delegate :decode, :to => :backend + + def backend=(name) + if name.is_a?(Module) + @backend = name + else + require "active_support/json/backends/#{name.to_s.downcase}.rb" + @backend = ActiveSupport::JSON::Backends::const_get(name) + end + end + + def with_backend(name) + old_backend, self.backend = backend, name + yield + ensure + self.backend = old_backend + end + end + end class << self def escape_html_entities_in_json @@ -19,7 +48,8 @@ module ActiveSupport @escape_html_entities_in_json = value end end + + JSON.backend = 'Yaml' end -require 'active_support/json/encoding' -require 'active_support/json/decoding' +require 'active_support/json/encoding'
\ No newline at end of file |