123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::JSON::Encoding::JSONGemCoderEncoder

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/json/encoding.rb

Constant Summary

Class Method Summary

Instance Method Summary

Constructor Details

.new(options = nil) ⇒ JSONGemCoderEncoder

[ GitHub ]

  
# File 'activesupport/lib/active_support/json/encoding.rb', line 137

def initialize(options = nil)
  @options = options ? options.dup.freeze : {}.freeze
end

Instance Method Details

#encode(value)

Encode the given object into a ::ActiveSupport::JSON string

[ GitHub ]

  
# File 'activesupport/lib/active_support/json/encoding.rb', line 142

def encode(value)
  value = value.as_json(@options) unless @options.empty?

  json = CODER.dump(value)

  # Rails does more escaping than the JSON gem natively does (we
  # escape \u2028 and \u2029 and optionally >, <, & to work around
  # certain browser problems).
  json.force_encoding(::Encoding::BINARY)
  if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json)
    json.gsub!(ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS)
  else
    json.gsub!(ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS)
  end
  json.force_encoding(::Encoding::UTF_8)
end