Class: ActiveRecord::Coders::JSON
- Inherits:
-
Object
- Object
- ActiveRecord::Coders::JSON
- Defined in:
- lib/active_record/coders/json.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_ENCODE_OPTIONS =
{ escape: false }.freeze
Instance Method Summary collapse
- #dump(obj) ⇒ Object
-
#initialize(encode_options: nil, decode_options: nil) ⇒ JSON
constructor
A new instance of JSON.
- #load(json) ⇒ Object
Constructor Details
#initialize(encode_options: nil, decode_options: nil) ⇒ JSON
Returns a new instance of JSON.
10 11 12 13 14 |
# File 'lib/active_record/coders/json.rb', line 10 def initialize(encode_options: nil, decode_options: nil) = ? DEFAULT_ENCODE_OPTIONS.merge() : DEFAULT_ENCODE_OPTIONS @decode_options = @encoder = ActiveSupport::JSON::Encoding.json_encoder.new() end |
Instance Method Details
#dump(obj) ⇒ Object
16 17 18 |
# File 'lib/active_record/coders/json.rb', line 16 def dump(obj) @encoder.encode(obj) end |
#load(json) ⇒ Object
20 21 22 |
# File 'lib/active_record/coders/json.rb', line 20 def load(json) ActiveSupport::JSON.decode(json, @decode_options) unless json.blank? end |