Sha256: b948835f3a5c656f192bc84303440de85e93545b102d6891151da963b7523a16

Contents?: true

Size: 804 Bytes

Versions: 9

Compression:

Stored size: 804 Bytes

Contents

module ActiveRecord
  module Type
    module Internal # :nodoc:
      class AbstractJson < ActiveModel::Type::Value # :nodoc:
        include ActiveModel::Type::Helpers::Mutable

        def type
          :json
        end

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

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

        def changed_in_place?(raw_old_value, new_value)
          deserialize(raw_old_value) != new_value
        end

        def accessor
          ActiveRecord::Store::StringKeyedHashAccessor
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.7.rc1 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.6.2 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.6.1 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.6 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.5 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.5.rc1 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.4 lib/active_record/type/internal/abstract_json.rb
activerecord-5.1.4.rc1 lib/active_record/type/internal/abstract_json.rb