Created
May 26, 2016 18:01
-
-
Save micahbf/db4d202832d03de60b2fe849808fb296 to your computer and use it in GitHub Desktop.
Find versions where a specific thing was changed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_PaperTrail_Version | |
def changes_to | |
raise ArgumentError, "block required" unless block_given? | |
result = [] | |
changes = scope.to_a.map do |version| | |
version_state = yield version.reify | |
[version_state, version] | |
end.each_cons(2).select do |old, new| | |
old.first != new.first | |
end | |
return [] if changes.empty? | |
changes << [changes.last.last, nil] | |
changes.map do |(state, version), _| | |
[state, {whodunnit: version.whodunnit, when: version.created_at, version_id: version.id}] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment