Class: ActiveSupport::JSON::Encoding::Encoder
- Defined in:
- activesupport/lib/active_support/json/encoding.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#as_json(value, use_options = true) ⇒ Object
like encode, but only calls as_json, without encoding to string.
- #encode(value, use_options = true) ⇒ Object
- #escape(string) ⇒ Object
-
#initialize(options = nil) ⇒ Encoder
constructor
A new instance of Encoder.
- #options_for(value) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Encoder
Returns a new instance of Encoder.
44 45 46 47 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 44 def initialize( = nil) @options = || {} @seen = Set.new end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options
42 43 44 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 42 def @options end |
Instance Method Details
#as_json(value, use_options = true) ⇒ Object
like encode, but only calls as_json, without encoding to string.
57 58 59 60 61 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 57 def as_json(value, = true) check_for_circular_references(value) do ? value.as_json((value)) : value.as_json end end |
#encode(value, use_options = true) ⇒ Object
49 50 51 52 53 54 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 49 def encode(value, = true) check_for_circular_references(value) do jsonified = ? value.as_json((value)) : value.as_json jsonified.encode_json(self) end end |
#escape(string) ⇒ Object
73 74 75 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 73 def escape(string) Encoding.escape(string) end |
#options_for(value) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'activesupport/lib/active_support/json/encoding.rb', line 63 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 .dup end end |