77module OctocatalogDiff
88 module CatalogDiff
99 class Filter
10- # Filter out changes in parameters when one catalog has a parameter that's a string and
11- # the other catalog has that same parameter as an array containing the same string .
10+ # Filter out changes in parameters when one catalog has a parameter that's an object and
11+ # the other catalog has that same parameter as an array containing the same object .
1212 # For example, under this filter, the following is not a change:
1313 # catalog1: notify => "Service[foo]"
1414 # catalog2: notify => ["Service[foo]"]
@@ -18,9 +18,27 @@ class SingleItemArray < OctocatalogDiff::CatalogDiff::Filter
1818 #
1919 # @param diff [OctocatalogDiff::API::V1::Diff] Difference
2020 # @param _options [Hash] Additional options (there are none for this filter)
21- # @return [Boolean] true if this difference is a YAML file with identical objects, false otherwise
22- def filtered? ( _diff , _options = { } )
23- false
21+ # @return [Boolean] true if this should be filtered out, false otherwise
22+ def filtered? ( diff , _options = { } )
23+ # Skip additions or removals - focus only on changes
24+ return false unless diff . change?
25+ old_value = diff . old_value
26+ new_value = diff . new_value
27+
28+ # Skip unless there is a single-item array under consideration
29+ return false unless
30+ ( old_value . is_a? ( Array ) && old_value . size == 1 ) ||
31+ ( new_value . is_a? ( Array ) && new_value . size == 1 )
32+
33+ # Skip if both the old value and new value are arrays
34+ return false if old_value . is_a? ( Array ) && new_value . is_a? ( Array )
35+
36+ # Do comparison
37+ if old_value . is_a? ( Array )
38+ old_value . first == new_value
39+ else
40+ new_value . first == old_value
41+ end
2442 end
2543 end
2644 end
0 commit comments