File: asymmetric_compare.rb

package info (click to toggle)
puppet-module-voxpupuli-elasticsearch 9.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,496 kB
  • sloc: ruby: 9,906; sh: 392; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Puppet_X # rubocop:disable Style/ClassAndModuleCamelCase
  # Custom Elastic functions
  module Elastic
    # Certain Elasticsearch APIs return fields that are present in responses
    # but not present when sending API requests such as creation time, and so
    # on. When comparing desired settings and extant settings, only indicate
    # that a value differs from another when user-desired settings differ from
    # existing settings - we ignore keys that exist in the response that aren't
    # being explicitly controlled by Puppet.
    def self.asymmetric_compare(should_val, is_val)
      should_val.reduce(true) do |is_synced, (should_key, should_setting)|
        if is_val.key? should_key
          if is_val[should_key].is_a? Hash
            asymmetric_compare(should_setting, is_val[should_key])
          else
            is_synced && is_val[should_key] == should_setting
          end
        else
          is_synced && true
        end
      end
    end
  end
end