1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Style/ClassEqualityComparison

This commit is contained in:
Jared Beck 2021-03-21 00:21:02 -04:00
parent 3a58f3f78c
commit c2c0f4e526
2 changed files with 24 additions and 14 deletions

View file

@ -153,7 +153,3 @@ RSpec/FilePath:
Exclude:
- 'spec/paper_trail/model_spec.rb'
- 'spec/paper_trail/serializer_spec.rb'
Style/ClassEqualityComparison:
Exclude:
- 'lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb'

View file

@ -8,18 +8,32 @@ module PaperTrail
# not suited for writing JSON to a text column. This factory
# replaces certain default Active Record serializers
# with custom PaperTrail ones.
#
# @api private
module AttributeSerializerFactory
AR_PG_ARRAY_CLASS = "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array"
class << self
# @api private
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
def self.for(klass, attr)
active_record_serializer = klass.type_for_attribute(attr)
if active_record_serializer.class.name == AR_PG_ARRAY_CLASS
TypeSerializers::PostgresArraySerializer.new(
active_record_serializer.subtype,
active_record_serializer.delimiter
)
else
active_record_serializer
private
# @api private
def ar_pg_array?(obj)
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
obj.instance_of?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
else
false
end
end
end
end