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 224

def initialize(options = nil)
  if options
    options = options.dup
    @escape = options.delete(:escape) { true }
    @options = options.freeze
  else
    @escape = true
    @options = {}.freeze
  end
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 236

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

  json = CODER.dump(value)

  return json unless @escape

  escape!(json)
end

#escape!(json) (private)

See additional method definition at line 248.

[ GitHub ]

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

def escape!(json)
  if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json)
    if Encoding.escape_js_separators_in_json
      json.tr!(UTF8_ESCAPED_CHARS)
    else
      json.tr!(UTF8_HTML_ENTITIES)
    end
  elsif Encoding.escape_js_separators_in_json
    json.tr!(UTF8_JS_SEPARATORS)
  end
  json
end