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:
parent
3a58f3f78c
commit
c2c0f4e526
2 changed files with 24 additions and 14 deletions
|
@ -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'
|
||||
|
|
|
@ -8,12 +8,14 @@ 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"
|
||||
|
||||
def self.for(klass, attr)
|
||||
class << self
|
||||
# @api private
|
||||
def for(klass, attr)
|
||||
active_record_serializer = klass.type_for_attribute(attr)
|
||||
if active_record_serializer.class.name == AR_PG_ARRAY_CLASS
|
||||
if ar_pg_array?(active_record_serializer)
|
||||
TypeSerializers::PostgresArraySerializer.new(
|
||||
active_record_serializer.subtype,
|
||||
active_record_serializer.delimiter
|
||||
|
@ -22,6 +24,18 @@ module PaperTrail
|
|||
active_record_serializer
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue