1 require 'active_support/json/variable'
2 require 'active_support/json/encoders/object' # Require explicitly for rdoc.
3 Dir
["#{File.dirname(__FILE__)}/encoders/**/*.rb"].each
do |file
|
4 basename
= File
.basename(file
, '.rb')
5 unless basename
== 'object'
6 require "active_support/json/encoders/#{basename}"
12 class CircularReferenceError
< StandardError
16 REFERENCE_STACK_VARIABLE
= :json_reference_stack #:nodoc:
18 # Converts a Ruby object into a JSON string.
19 def encode(value
, options
= {})
20 raise_on_circular_reference(value
) do
21 value
.send(:to_json, options
)
26 def raise_on_circular_reference(value
) #:nodoc:
27 stack
= Thread
.current
[REFERENCE_STACK_VARIABLE
] ||= []
28 raise CircularReferenceError
, 'object references itself' if