7
7
module OctocatalogDiff
8
8
module CatalogDiff
9
9
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 .
12
12
# For example, under this filter, the following is not a change:
13
13
# catalog1: notify => "Service[foo]"
14
14
# catalog2: notify => ["Service[foo]"]
@@ -18,9 +18,27 @@ class SingleItemArray < OctocatalogDiff::CatalogDiff::Filter
18
18
#
19
19
# @param diff [OctocatalogDiff::API::V1::Diff] Difference
20
20
# @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
24
42
end
25
43
end
26
44
end
0 commit comments