Skip to content

Commit

Permalink
Deprecate #clear_changed_attributes (#1407)
Browse files Browse the repository at this point in the history
This method can be replaced by `ActiveModel::Dirty#changes_applied`, which is
more resiliant to changing `ActiveModel` and `Rails` behavior.

However, since we call it in a callback, and downstream users may be relying on
that fact to trigger calls to their overrides, we continue calling it in the
case that it is both: not the base definition, and not the version overridden in
`ListSource`.

Callers to those two versions will see deprecation warnings, and users of the
callback will also see deprecation warnings. Their local behavior may be in
conflict with Rails 6.0.
  • Loading branch information
Tom Johnson authored Sep 18, 2019
1 parent e6a5f1a commit 019f401
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/active_fedora/aggregation/list_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def save(*args)
super
end

##
# @deprecated use #changes_applied instead
def clear_changed_attributes
Deprecation.warn self.class, "#clear_changed_attributes is deprecated, use ActiveModel::Dirty#changes_applied instead."

clear_changes_information
end

def changed?
super || ordered_self.changed?
end
Expand Down
25 changes: 24 additions & 1 deletion lib/active_fedora/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,30 @@ module Attributes
include Serializers
include PrimaryKey

after_save :changes_applied
after_save :clear_changed_attributes_or_changes_applied
# @deprecated use #changes_applied instead
def clear_changed_attributes
Deprecation.warn ActiveFedora::Attributes, "#clear_changed_attributes is deprecated, use ActiveModel::Dirty#changes_applied instead."
@previously_changed = changes
clear_attribute_changes(changes.keys)
end

##
# Call the deprecated method
#
# @deprecated use #changes_applied instead
# @api private
def clear_changed_attributes_or_changes_applied
return changes_applied if
method(:clear_changed_attributes).super_method.nil? ||
method(:clear_changed_attributes).owner == ActiveFedora::Aggregation::ListSource

Deprecation.warn self.class, "after_save callbacks to #clear_changed_attributes are deprecated. " /
"These calls will be removed in 14.0.0. If you are running Rails 6.0, " /
"it's likely your #clear_changed_attributes implementation is in " /
"conflict with new ActiveModel::Dirty behavior."
clear_changed_attributes
end
end

def attribute_names
Expand Down

0 comments on commit 019f401

Please sign in to comment.