diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-02-25 00:21:45 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2013-02-25 00:21:45 -0500 |
commit | 3762ee0baa2285bdc4a76d4d492fbe34a10cdc3a (patch) | |
tree | 91977364867788abbc626f96680f5edd7243b7a2 | |
parent | 15d693df93cd1ec0fc27d617582d2f73036c335e (diff) | |
download | rails-3762ee0baa2285bdc4a76d4d492fbe34a10cdc3a.tar.gz rails-3762ee0baa2285bdc4a76d4d492fbe34a10cdc3a.tar.bz2 rails-3762ee0baa2285bdc4a76d4d492fbe34a10cdc3a.zip |
Revert "Simplify code in AS json encoder"
This reverts commit 046e27a7338f2961c10e9d133e0e2229b51c2ba8.
Check https://github.com/rails/rails/pull/8815#issuecomment-14026122 for
details.
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 8f5db5968c..9bf1ea35b3 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -38,6 +38,7 @@ module ActiveSupport class CircularReferenceError < StandardError; end class Encoder + attr_reader :options def initialize(options = nil) @options = options || {} @@ -62,9 +63,9 @@ module ActiveSupport if value.is_a?(Array) || value.is_a?(Hash) # hashes and arrays need to get encoder in the options, so that # they can detect circular references. - @options.merge(:encoder => self) + options.merge(:encoder => self) else - @options.dup + options.dup end end @@ -252,6 +253,18 @@ end module Enumerable def as_json(options = nil) #:nodoc: + to_a.as_json(options) + end +end + +class Range + def as_json(options = nil) #:nodoc: + to_s + end +end + +class Array + def as_json(options = nil) #:nodoc: # use encoder as a proxy to call as_json on all elements, to protect from circular references encoder = options && options[:encoder] || ActiveSupport::JSON::Encoding::Encoder.new(options) map { |v| encoder.as_json(v, options) } @@ -263,12 +276,6 @@ module Enumerable end end -class Range - def as_json(options = nil) #:nodoc: - to_s - end -end - class Hash def as_json(options = nil) #:nodoc: # create a subset of the hash by applying :only or :except |