Style/ClassEqualityComparison
This commit is contained in:
parent
3a58f3f78c
commit
c2c0f4e526
|
@ -153,7 +153,3 @@ RSpec/FilePath:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/paper_trail/model_spec.rb'
|
- 'spec/paper_trail/model_spec.rb'
|
||||||
- 'spec/paper_trail/serializer_spec.rb'
|
- 'spec/paper_trail/serializer_spec.rb'
|
||||||
|
|
||||||
Style/ClassEqualityComparison:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb'
|
|
||||||
|
|
|
@ -8,18 +8,32 @@ module PaperTrail
|
||||||
# not suited for writing JSON to a text column. This factory
|
# not suited for writing JSON to a text column. This factory
|
||||||
# replaces certain default Active Record serializers
|
# replaces certain default Active Record serializers
|
||||||
# with custom PaperTrail ones.
|
# with custom PaperTrail ones.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
module AttributeSerializerFactory
|
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)
|
private
|
||||||
active_record_serializer = klass.type_for_attribute(attr)
|
|
||||||
if active_record_serializer.class.name == AR_PG_ARRAY_CLASS
|
# @api private
|
||||||
TypeSerializers::PostgresArraySerializer.new(
|
def ar_pg_array?(obj)
|
||||||
active_record_serializer.subtype,
|
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
|
||||||
active_record_serializer.delimiter
|
obj.instance_of?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
|
||||||
)
|
else
|
||||||
else
|
false
|
||||||
active_record_serializer
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue