Delete LegacyActiveRecordShim 🎉
We no longer support rails < 4.2
This commit is contained in:
parent
728ecd6e90
commit
9db3b3ce05
|
@ -6,8 +6,7 @@ module PaperTrail
|
|||
# to an attribute of type `ActiveRecord::Type::Integer`.
|
||||
#
|
||||
# This implementation depends on the `type_for_attribute` method, which was
|
||||
# introduced in rails 4.2. In older versions of rails, we shim this method
|
||||
# with `LegacyActiveRecordShim`.
|
||||
# introduced in rails 4.2. As of PT 8, we no longer support rails < 4.2.
|
||||
class CastAttributeSerializer
|
||||
def initialize(klass)
|
||||
@klass = klass
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
module PaperTrail
|
||||
module AttributeSerializers
|
||||
# Included into model if AR version is < 4.2. Backport Rails 4.2 and later's
|
||||
# `type_for_attribute` so we can build on a common interface.
|
||||
module LegacyActiveRecordShim
|
||||
# An attribute which needs no processing. It is part of our backport (shim)
|
||||
# of rails 4.2's attribute API. See `type_for_attribute` below.
|
||||
class NoOpAttribute
|
||||
def type_cast_for_database(value)
|
||||
value
|
||||
end
|
||||
|
||||
def type_cast_from_database(data)
|
||||
data
|
||||
end
|
||||
end
|
||||
NO_OP_ATTRIBUTE = NoOpAttribute.new
|
||||
|
||||
# An attribute which requires manual (de)serialization to/from what we get
|
||||
# from the database. It is part of our backport (shim) of rails 4.2's
|
||||
# attribute API. See `type_for_attribute` below.
|
||||
class SerializedAttribute
|
||||
def initialize(coder)
|
||||
@coder = coder.respond_to?(:dump) ? coder : PaperTrail.serializer
|
||||
end
|
||||
|
||||
def type_cast_for_database(value)
|
||||
@coder.dump(value)
|
||||
end
|
||||
|
||||
def type_cast_from_database(data)
|
||||
@coder.load(data)
|
||||
end
|
||||
end
|
||||
|
||||
def type_for_attribute(attr_name)
|
||||
serialized_attribute_types[attr_name.to_s] || NO_OP_ATTRIBUTE
|
||||
end
|
||||
|
||||
def serialized_attribute_types
|
||||
@attribute_types ||= Hash[serialized_attributes.map do |attr_name, coder|
|
||||
[attr_name, SerializedAttribute.new(coder)]
|
||||
end]
|
||||
end
|
||||
private :serialized_attribute_types
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,4 @@
|
|||
require "active_support/core_ext/object" # provides the `try` method
|
||||
require "paper_trail/attribute_serializers/legacy_active_record_shim"
|
||||
require "paper_trail/attribute_serializers/object_attribute"
|
||||
require "paper_trail/attribute_serializers/object_changes_attribute"
|
||||
require "paper_trail/model_config"
|
||||
|
|
|
@ -79,13 +79,6 @@ module PaperTrail
|
|||
options[:on] ||= %i[create update destroy]
|
||||
options[:on] = Array(options[:on]) # Support single symbol
|
||||
@model_class.send :include, ::PaperTrail::Model::InstanceMethods
|
||||
if ::ActiveRecord::VERSION::STRING < "4.2"
|
||||
::ActiveSupport::Deprecation.warn(
|
||||
"Your version of ActiveRecord (< 4.2) has reached EOL. PaperTrail " \
|
||||
"will soon drop support. Please upgrade ActiveRecord ASAP."
|
||||
)
|
||||
@model_class.send :extend, AttributeSerializers::LegacyActiveRecordShim
|
||||
end
|
||||
setup_options(options)
|
||||
setup_associations(options)
|
||||
setup_transaction_callbacks
|
||||
|
|
Loading…
Reference in New Issue