Skip to content

Commit

Permalink
Quick and dirty fix of Dymanoid::Dirty and Rails 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Apr 25, 2018
1 parent 0262a52 commit 8deafbf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/dynamoid/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Dirty

module ClassMethods
def from_database(*)
super.tap { |d| d.changed_attributes.clear }
super.tap { |d| d.send(:clear_changes_information) }
end
end

Expand All @@ -28,7 +28,7 @@ def clear_changes
(block_given? ? yield : true).tap do |result|
unless result == false # failed validation; nil is OK.
@previously_changed = previous
changed_attributes.clear
clear_changes_information
end
end
end
Expand All @@ -43,5 +43,18 @@ def write_attribute(name, value)
def attribute_method?(attr)
super || self.class.attributes.has_key?(attr.to_sym)
end

if ActiveModel::VERSION::STRING >= '5.2.0'
# The ActiveModel::Dirty API was changed
# https://github.com/rails/rails/commit/c3675f50d2e59b7fc173d7b332860c4b1a24a726#diff-aaddd42c7feb0834b1b5c66af69814d3
# So we just try to disable new functionality

def mutations_from_database
@mutations_from_database ||= ActiveModel::NullMutationTracker.instance
end

def forget_attribute_assignments
end
end
end
end

0 comments on commit 8deafbf

Please sign in to comment.