plugins/model/unmanaged_files_model.rb in machinery-tool-1.0.2 vs plugins/model/unmanaged_files_model.rb in machinery-tool-1.1.0
- old
+ new
@@ -13,17 +13,45 @@
# along with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
+require_relative "file_scope"
class UnmanagedFile < Machinery::Object
end
class UnmanagedFileList < Machinery::Array
has_elements class: UnmanagedFile
+
+ def compare_with(other)
+ only_self = elements.reject do |element|
+ other.elements.find { |other_element| files_match(element, other_element) }
+ end
+ only_other = other.elements.reject do |element|
+ elements.find { |other_element| files_match(element, other_element) }
+ end
+ both = elements.select do |element|
+ other.elements.find { |other_element| files_match(element, other_element) }
+ end
+
+ [
+ self.class.new(only_self),
+ self.class.new(only_other),
+ self.class.new(both)
+ ].map { |e| !e.empty? ? e : nil }
+ end
+
+ private
+
+ def files_match(a, b)
+ common_attributes = a.attributes.keys & b.attributes.keys
+ common_attributes.all? do |attribute|
+ a[attribute] == b[attribute]
+ end
+ end
end
-class UnmanagedFilesScope < Machinery::Object
+class UnmanagedFilesScope < FileScope
include Machinery::ScopeMixin
has_property :files, class: UnmanagedFileList
end