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