Class: ActiveSupport::JSON::Encoding::Encoder
- Inherits:
-
Object
- Object
- ActiveSupport::JSON::Encoding::Encoder
- Defined in:
- activesupport/lib/active_support/json/encoding.rb
Instance Attribute Summary (collapse)
-
- (Object) options
readonly
Returns the value of attribute options.
Instance Method Summary (collapse)
-
- (Object) as_json(value)
like encode, but only calls as_json, without encoding to string.
- - (Object) encode(value, use_options = true)
- - (Object) escape(string)
-
- (Encoder) initialize(options = nil)
constructor
A new instance of Encoder.
- - (Object) options_for(value)
Constructor Details
- (Encoder) initialize(options = nil)
A new instance of Encoder
39 40 41 42 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 39 def initialize( = nil) @options = @seen = [] end |
Instance Attribute Details
- (Object) options (readonly)
Returns the value of attribute options
37 38 39 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 37 def @options end |
Instance Method Details
- (Object) as_json(value)
like encode, but only calls as_json, without encoding to string
52 53 54 55 56 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 52 def as_json(value) check_for_circular_references(value) do value.as_json((value)) end end |
- (Object) encode(value, use_options = true)
44 45 46 47 48 49 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 44 def encode(value, = true) check_for_circular_references(value) do jsonified = ? value.as_json((value)) : value.as_json jsonified.encode_json(self) end end |
- (Object) escape(string)
67 68 69 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 67 def escape(string) Encoding.escape(string) end |
- (Object) options_for(value)
58 59 60 61 62 63 64 65 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 58 def (value) 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 ( || {}).merge(:encoder => self) else end end |