Class: RapidJSON::ActiveSupportEncoder
- Inherits:
-
Object
- Object
- RapidJSON::ActiveSupportEncoder
- Defined in:
- lib/rapidjson/active_support_encoder.rb
Instance Method Summary collapse
-
#encode(value) ⇒ Object
Encode the given object into a JSON string.
-
#initialize(options = nil) ⇒ ActiveSupportEncoder
constructor
A new instance of ActiveSupportEncoder.
Constructor Details
#initialize(options = nil) ⇒ ActiveSupportEncoder
Returns a new instance of ActiveSupportEncoder.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/rapidjson/active_support_encoder.rb', line 3 def initialize( = nil) @options = @coder = RapidJSON::Coder.new do |value, is_key| if is_key value.to_s else value.as_json end end end |
Instance Method Details
#encode(value) ⇒ Object
Encode the given object into a JSON string
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rapidjson/active_support_encoder.rb', line 15 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 |