Class: ActiveRecord::Coders::JSON

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/coders/json.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_OPTIONS =
{ escape: false }.freeze

Instance Method Summary collapse

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(options = nil)
  @options = options ? DEFAULT_OPTIONS.merge(options) : DEFAULT_OPTIONS
  @encoder = ActiveSupport::JSON::Encoding.json_encoder.new(options)
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