Top Level Namespace

Defined Under Namespace

Modules: Cli Classes: ArgMissingError, BaseTransmogrifier, BoshDeploymentManifest, BoshDeploymentManifestConfigTransmogrifier, Configgin, EnvironmentConfigTransmogrifier, Job, KubeDNSEncoder, KubeLinkSpecs, LinkResolveError, LoadYamlFromMustacheError, NoDataProvided, NonHashValueOverride

Instance Method Summary collapse

Instance Method Details

#property_digest(properties) ⇒ Object

Given a properties (a JSON-serializable Hash), generate a digest that will be consistent across runs even if the enumeration order of hashes changes.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/property_digest.rb', line 6

def property_digest(properties)
  normalize_object = lambda do |obj|
    case obj
    when Hash
      {}.tap { |result| obj.sort.each { |k, v| result[k] = normalize_object.call(v) } }
    when Enumerable
      obj.map(&normalize_object)
    else
      obj
    end
  end
  "sha1:#{Digest::SHA1.hexdigest(normalize_object.call(properties).to_json)}"
end