|
|
|
@ -85,31 +85,45 @@ class JournalManager |
|
|
|
|
# This would lead to false change information, otherwise. |
|
|
|
|
# We need to be careful though, because we want to accept false (and false.blank? == true) |
|
|
|
|
def self.remove_empty_associations(associations, value) |
|
|
|
|
associations.reject { |h| h.has_key?(value) && h[value].blank? && h[value] != false } |
|
|
|
|
associations.reject { |association| |
|
|
|
|
association.has_key?(value) && |
|
|
|
|
association[value].blank? && |
|
|
|
|
association[value] != false |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.merge_reference_journals_by_id(current, predecessor, key) |
|
|
|
|
all_attachable_journal_ids = current.map { |j| j[key] } | predecessor.map { |j| j[key] } |
|
|
|
|
def self.merge_reference_journals_by_id(new_journals, old_journals, id_key) |
|
|
|
|
all_associated_journal_ids = new_journals.map { |j| j[id_key] } | |
|
|
|
|
old_journals.map { |j| j[id_key] } |
|
|
|
|
|
|
|
|
|
all_attachable_journal_ids.each_with_object({}) { |i, h| |
|
|
|
|
h[i] = [predecessor.detect { |j| j[key] == i }, |
|
|
|
|
current.detect { |j| j[key] == i }] |
|
|
|
|
all_associated_journal_ids.each_with_object({}) { |id, result| |
|
|
|
|
result[id] = [old_journals.detect { |j| j[id_key] == id }, |
|
|
|
|
new_journals.detect { |j| j[id_key] == id }] |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.added_references(merged_references, key, value) |
|
|
|
|
merged_references.select { |_, v| v[0].nil? and not v[1].nil? } |
|
|
|
|
.each_with_object({}) { |k, h| h["#{key}_#{k[0]}"] = [nil, k[1][1][value]] } |
|
|
|
|
merged_references.select { |_, (old_attributes, new_attributes)| |
|
|
|
|
old_attributes.nil? && !new_attributes.nil? |
|
|
|
|
}.each_with_object({}) { |(id, (_, new_attributes)), result| |
|
|
|
|
result["#{key}_#{id}"] = [nil, new_attributes[value]] |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.removed_references(merged_references, key, value) |
|
|
|
|
merged_references.select { |_, v| not v[0].nil? and v[1].nil? } |
|
|
|
|
.each_with_object({}) { |k, h| h["#{key}_#{k[0]}"] = [k[1][0][value], nil] } |
|
|
|
|
merged_references.select { |_, (old_attributes, new_attributes)| |
|
|
|
|
!old_attributes.nil? && new_attributes.nil? |
|
|
|
|
}.each_with_object({}) { |(id, (old_attributes, _)), result| |
|
|
|
|
result["#{key}_#{id}"] = [old_attributes[value], nil] |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.changed_references(merged_references, key, value) |
|
|
|
|
merged_references.select { |_, v| not v[0].nil? and not v[1].nil? and v[0][value] != v[1][value] } |
|
|
|
|
.each_with_object({}) { |k, h| h["#{key}_#{k[0]}"] = [k[1][0][value], k[1][1][value]] } |
|
|
|
|
merged_references.select { |_, (old_attributes, new_attributes)| |
|
|
|
|
!old_attributes.nil? && !new_attributes.nil? && old_attributes[value] != new_attributes[value] |
|
|
|
|
}.each_with_object({}) { |(id, (old_attributes, new_attributes)), result| |
|
|
|
|
result["#{key}_#{id}"] = [old_attributes[value], new_attributes[value]] |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def self.recreate_initial_journal(type, journal, changed_data) |
|
|
|
|