Sha256: 7198e856aec5260f82006c69964e719764a0d7b5a9c3f3584af7e032cb910964

Contents?: true

Size: 717 Bytes

Versions: 2

Compression:

Stored size: 717 Bytes

Contents

module RapidJSON
  class ActiveSupportEncoder
    def initialize(options = nil)
      @options = options
      @coder = RapidJSON::Coder.new do |value, is_key|
        if is_key
          value.to_s
        else
          value.as_json
        end
      end
    end

    # Encode the given object into a JSON string
    def encode(value)
      if @options && !@options.empty?
        if !RapidJSON.json_ready?(value) || @options.key?(:only) || @options.key?(:except)
          value = value.as_json(@options.dup)
        end
      end
      json = @coder.dump(value)
      if ActiveSupport::JSON::Encoding.escape_html_entities_in_json
        json = RapidJSON.json_escape(json)
      end
      json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapidjson-0.4.0 lib/rapidjson/active_support_encoder.rb
rapidjson-0.3.0 lib/rapidjson/active_support_encoder.rb