Fix NameError when pg is not loaded

Most apps only load a single db adapter gem.

A MySQL app, for example will not load the pg gem.

See https://github.com/airblade/paper_trail/issues/1022
This commit is contained in:
Jared Beck 2017-12-10 02:16:26 -05:00
parent 33f75c6608
commit 932bf22347
1 changed files with 3 additions and 2 deletions

View File

@ -7,10 +7,11 @@ module PaperTrail
# replaces certain default Active Record serializers
# with custom PaperTrail ones.
module AttributeSerializerFactory
AR_PG_ARRAY_CLASS = "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array".freeze
def self.for(klass, attr)
active_record_serializer = klass.type_for_attribute(attr)
case active_record_serializer
when ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array then
if active_record_serializer.class.name == AR_PG_ARRAY_CLASS
TypeSerializers::PostgresArraySerializer.new(
active_record_serializer.subtype,
active_record_serializer.delimiter