Class: ActiveSupport::JSON::Encoding::JSONGemEncoder
- Defined in:
- lib/active_support/json/encoding.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#encode(value) ⇒ Object
Encode the given object into a JSON string.
-
#initialize(options = nil) ⇒ JSONGemEncoder
constructor
A new instance of JSONGemEncoder.
Constructor Details
#initialize(options = nil) ⇒ JSONGemEncoder
Returns a new instance of JSONGemEncoder.
50 51 52 |
# File 'lib/active_support/json/encoding.rb', line 50 def initialize( = nil) @options = || {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
48 49 50 |
# File 'lib/active_support/json/encoding.rb', line 48 def @options end |
Instance Method Details
#encode(value) ⇒ Object
Encode the given object into a JSON string
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_support/json/encoding.rb', line 55 def encode(value) unless .empty? value = value.as_json(.dup.freeze) end json = stringify(jsonify(value)) # Rails does more escaping than the JSON gem natively does (we # escape \u2028 and \u2029 and optionally >, <, & to work around # certain browser problems). if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json) json.gsub!(">", '\u003e') json.gsub!("<", '\u003c') json.gsub!("&", '\u0026') end json.gsub!("\u2028", '\u2028') json.gsub!("\u2029", '\u2029') json end |