lib/eco/data/hashes/array_diff.rb in eco-helpers-2.4.6 vs lib/eco/data/hashes/array_diff.rb in eco-helpers-2.4.7
- old
+ new
@@ -54,18 +54,27 @@
# @note
# - A `Hash::DiffResult` object, offers `hash_diff` with the attrs that have changed value
# - It also allows to know the original value
# @return [Hash] where `key` is the key of the record, and `value` a `DiffResult` object
def diffs
- @diffs ||= paired_sources.each_with_object([]) do |(src1, src2), diffs|
+ @diffs ||= source_results.select do |res|
+ res.diff?
+ end
+ end
+
+ # @return [Boolean] wheter or not there are differences.
+ def diffs?
+ !diffs.empty?
+ end
+
+ def source_results
+ @source_results ||= paired_sources.each_with_object([]) do |(src1, src2), res|
args = {
key: key,
compare: compared_attrs,
case_sensitive: case_sensitive?
}
- diff_result_class.new(src1, src2, **args).tap do |res|
- diffs << res if res.diff?
- end
+ res << diff_result_class.new(src1, src2, **args)
end
end
protected