Class: OctocatalogDiff::CatalogDiff::Filter::SingleItemArray
- Inherits:
-
OctocatalogDiff::CatalogDiff::Filter
- Object
- OctocatalogDiff::CatalogDiff::Filter
- OctocatalogDiff::CatalogDiff::Filter::SingleItemArray
- Defined in:
- lib/octocatalog-diff/catalog-diff/filter/single_item_array.rb
Overview
Filter out changes in parameters when one catalog has a parameter that’s an object and the other catalog has that same parameter as an array containing the same object. For example, under this filter, the following is not a change:
catalog1: notify => "Service[foo]"
catalog2: notify => ["Service[foo]"]
Constant Summary
Constants inherited from OctocatalogDiff::CatalogDiff::Filter
Instance Attribute Summary
Attributes inherited from OctocatalogDiff::CatalogDiff::Filter
Instance Method Summary collapse
-
#filtered?(diff, _options = {}) ⇒ Boolean
Public: Implement the filter for single-item arrays whose item exactly matches the item that’s not in an array in the other catalog.
Methods inherited from OctocatalogDiff::CatalogDiff::Filter
apply_filters, assert_that_filter_exists, filter, filter?, #initialize
Constructor Details
This class inherits a constructor from OctocatalogDiff::CatalogDiff::Filter
Instance Method Details
#filtered?(diff, _options = {}) ⇒ Boolean
Public: Implement the filter for single-item arrays whose item exactly matches the item that’s not in an array in the other catalog.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/octocatalog-diff/catalog-diff/filter/single_item_array.rb', line 20 def filtered?(diff, = {}) # Skip additions or removals - focus only on changes return false unless diff.change? old_value = diff.old_value new_value = diff.new_value # Skip unless there is a single-item array under consideration return false unless (old_value.is_a?(Array) && old_value.size == 1) || (new_value.is_a?(Array) && new_value.size == 1) # Skip if both the old value and new value are arrays return false if old_value.is_a?(Array) && new_value.is_a?(Array) # Do comparison if old_value.is_a?(Array) old_value.first == new_value else new_value.first == old_value end end |