Skip to content

Commit 7bde1b7

Browse files
committed
Fix ActiveSupport 5.1 deprecation warnings.
1 parent f03ebd7 commit 7bde1b7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/closure_tree/hierarchy_maintenance.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def _ct_before_save
3535
end
3636

3737
def _ct_after_save
38-
if changes[_ct.parent_column_name] || @was_new_record
38+
as_5_1 = ActiveSupport.version >= Gem::Version.new('5.1.0')
39+
changes_method = as_5_1 ? :saved_changes : :changes
40+
41+
if public_send(changes_method)[_ct.parent_column_name] || @was_new_record
3942
rebuild!
4043
end
41-
if changes[_ct.parent_column_name] && !@was_new_record
44+
if public_send(changes_method)[_ct.parent_column_name] && !@was_new_record
4245
# Resetting the ancestral collections addresses
4346
# https://github.com/mceachen/closure_tree/issues/68
4447
ancestor_hierarchies.reload

lib/closure_tree/numeric_deterministic_ordering.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ module NumericDeterministicOrdering
1010
end
1111

1212
def _ct_reorder_prior_siblings_if_parent_changed
13-
if attribute_changed?(_ct.parent_column_name) && !@was_new_record
14-
was_parent_id = attribute_was(_ct.parent_column_name)
13+
as_5_1 = ActiveSupport.version >= Gem::Version.new('5.1.0')
14+
change_method = as_5_1 ? :saved_change_to_attribute? : :attribute_changed?
15+
16+
if public_send(change_method, _ct.parent_column_name) && !@was_new_record
17+
attribute_method = as_5_1 ? :attribute_before_last_save : :attribute_was
18+
19+
was_parent_id = public_send(attribute_method, _ct.parent_column_name)
1520
_ct.reorder_with_parent_id(was_parent_id)
1621
end
1722
end

0 commit comments

Comments
 (0)