Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

get attributes using method calls instead of attributes hash to allow "virtual" attributes

Ivan Kuchinaf0247249dc4
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/differ/association.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/differ/association.rb
index 3cb490eba91..28fbafffa35 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/differ/association.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/differ/association.rb
@@ -31,8 +31,8 @@
module Acts::Journalized::Differ
class Association
def initialize(original, changed, association:, id_attribute:)
- @original_by_id = attributes_by_id(original, association, id_attribute)
- @changed_by_id = attributes_by_id(changed, association, id_attribute)
+ @original_by_id = association_by_id(original, association, id_attribute)
+ @changed_by_id = association_by_id(changed, association, id_attribute)
@ids = (@changed_by_id.keys | @original_by_id.keys).compact
end
@@ -56,22 +56,20 @@ module Acts::Journalized::Differ
private
- def attributes_by_id(model, association, id_attribute)
+ def association_by_id(model, association, id_attribute)
return {} unless model
- id_attribute = id_attribute.to_s
-
relation = if association.respond_to?(:call)
association.call(model)
else
model.send(association)
end
- relation.map(&:attributes).group_by { _1[id_attribute] }
+ relation.group_by(&id_attribute.to_sym)
end
def single_attribute_changes(attribute)
- attribute = attribute.to_s
+ attribute = attribute.to_sym
pairs = @ids.index_with do |id|
[
@@ -85,7 +83,7 @@ module Acts::Journalized::Differ
def combine_journals(journals, attribute)
# TODO: is there real case where there will be more than one value?
- journals.pluck(attribute).sort.join(",") if journals
+ journals.map(&attribute).sort.join(",") if journals
end
end
end