Sha256: 90ac6be0afe46ab04bbc33a181e01cc78a64b391b3c0b22078162992be647b57

Contents?: true

Size: 1.63 KB

Versions: 20

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require_relative '../filter'

require 'yaml'

module OctocatalogDiff
  module CatalogDiff
    class Filter
      # Filter based on equivalence of YAML objects for file resources with named extensions.
      class YAML < OctocatalogDiff::CatalogDiff::Filter
        # 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.
        #
        # @param diff_in [OctocatalogDiff::API::V1::Diff] Difference
        # @param _options [Hash] Additional options (there are none for this filter)
        # @return [Boolean] true if this difference is a YAML file with identical objects, false otherwise
        def filtered?(diff, _options = {})
          # 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
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
octocatalog-diff-2.3.1 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-2.3.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-2.1.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-2.0.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.6.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.5.4 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.5.3 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.5.2 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.5.1 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.5.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.4.1 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.4.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.3.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.2.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.1.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.0.4 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.0.3 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.0.2 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.0.1 lib/octocatalog-diff/catalog-diff/filter/yaml.rb
octocatalog-diff-1.0.0 lib/octocatalog-diff/catalog-diff/filter/yaml.rb