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

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

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ActiveModel::Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from ActiveModel::Type::Helpers::Mutable

#cast, #changed_in_place?

Methods inherited from ActiveModel::Type::Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #hash, #initialize, #map, #type_cast_for_schema

Constructor Details

This class inherits a constructor from ActiveModel::Type::Value

Instance Method Details

#accessorObject


27
28
29
# File 'activerecord/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 'activerecord/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 'activerecord/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 'activerecord/lib/active_record/type/internal/abstract_json.rb', line 7

def type
  :json
end