Class: ActiveRecord::Type::Internal::AbstractJson

Inherits:
ActiveModel::Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
lib/active_record/type/internal/abstract_json.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#accessorObject


27
28
29
# File 'lib/active_record/type/internal/abstract_json.rb', line 27

def accessor
  ActiveRecord::Store::StringKeyedHashAccessor
end

#deserialize(value) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/active_record/type/internal/abstract_json.rb', line 11

def deserialize(value)
  if value.is_a?(::String)
    ::ActiveSupport::JSON.decode(value) rescue nil
  else
    value
  end
end

#serialize(value) ⇒ Object


19
20
21
22
23
24
25
# File 'lib/active_record/type/internal/abstract_json.rb', line 19

def serialize(value)
  if value.nil?
    nil
  else
    ::ActiveSupport::JSON.encode(value)
  end
end

#typeObject


7
8
9
# File 'lib/active_record/type/internal/abstract_json.rb', line 7

def type
  :json
end