7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/log_book/squash_records.rb', line 7
def call
records.group_by(&:parent).each do |parent, children|
next if parent.nil?
children_to_squash = children.select { |child| child.subject.try(:to_squash?) }
next if children_to_squash.empty?
parent_in_records = parent_in_records(parent)
parent_in_records.record_changes.merge!(squashed_changes(children_to_squash, :record_changes))
parent_in_records.meta.merge!(squashed_changes(children_to_squash, :meta))
parent_in_records.created_at ||= children_to_squash.first.created_at
parent_in_records.save
children_to_squash.each(&:delete)
end
end
|