diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-05 18:25:07 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-08 13:21:30 -0700 |
commit | 00ee990443189649e481b2c30945e7a1029d8280 (patch) | |
tree | c30e731055da3a6f67ea4c154059ff7245ef6e1c /activesupport/lib/active_support/json/decoding.rb | |
parent | 5e1b46d4c285124737abe2e08dec97e4af1f4be7 (diff) | |
download | rails-00ee990443189649e481b2c30945e7a1029d8280.tar.gz rails-00ee990443189649e481b2c30945e7a1029d8280.tar.bz2 rails-00ee990443189649e481b2c30945e7a1029d8280.zip |
JSON: split encoding and coercion
Diffstat (limited to 'activesupport/lib/active_support/json/decoding.rb')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb new file mode 100644 index 0000000000..5d4caa362f --- /dev/null +++ b/activesupport/lib/active_support/json/decoding.rb @@ -0,0 +1,35 @@ +require 'active_support/core_ext/module/attribute_accessors' + +module ActiveSupport + # Look for and parse json strings that look like ISO 8601 times. + mattr_accessor :parse_json_times + + module JSON + class << self + delegate :decode, :to => :backend + + def backend + @backend || begin + self.backend = "Yaml" + @backend + end + end + + 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 +end |