Class: OctocatalogDiff::CatalogDiff::Filter::YAML
- Inherits:
-
OctocatalogDiff::CatalogDiff::Filter
- Object
- OctocatalogDiff::CatalogDiff::Filter
- OctocatalogDiff::CatalogDiff::Filter::YAML
- Defined in:
- lib/octocatalog-diff/catalog-diff/filter/yaml.rb
Overview
Filter based on equivalence of YAML objects for file resources with named extensions.
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: Actually do the comparison of YAML objects for appropriate resources.
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: Actually do the comparison of YAML objects for appropriate resources. Return true if the YAML objects are known to be equivalent. Return false if they are not equivalent, or if equivalence cannot be determined.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/octocatalog-diff/catalog-diff/filter/yaml.rb', line 19 def filtered?(diff, = {}) # Skip additions or removals - focus only on changes return false unless diff.change? # Make sure we are comparing file content for a file ending in .yaml or .yml extension return false unless diff.type == 'File' && diff.structure == %w(parameters content) return false unless diff.title =~ /\.ya?ml\z/ # Attempt to convert the old value and new value into YAML objects. Assuming # that doesn't error out, the return value is whether or not they're equal. obj_old = ::YAML.load(diff.old_value) obj_new = ::YAML.load(diff.new_value) obj_old == obj_new rescue # Rescue everything - if something failed, we aren't sure what's going on, so we'll return false. false end |