module PaperTrail::AttributeSerializers::AttributeSerializerFactory

Values returned by some Active Record serializers are not suited for writing JSON to a text column. This factory replaces certain default Active Record serializers with custom PaperTrail ones.

@api private

Public Class Methods

for(klass, attr) click to toggle source

@api private

# File lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb, line 16
def for(klass, attr)
  active_record_serializer = klass.type_for_attribute(attr)
  if ar_pg_array?(active_record_serializer)
    TypeSerializers::PostgresArraySerializer.new(
      active_record_serializer.subtype,
      active_record_serializer.delimiter
    )
  else
    active_record_serializer
  end
end

Private Class Methods

ar_pg_array?(obj) click to toggle source

@api private

# File lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb, line 31
def ar_pg_array?(obj)
  if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
    obj.instance_of?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
  else
    false
  end
end