Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/149775
Change subject: wmflib: add ordered_yaml() ...................................................................... wmflib: add ordered_yaml() Like ordered_json(), ordered_yaml() serializes a hash into YAML with lexicographically sorted keys. Ruby 1.9+ hashes maintain insertion order. The serialized form of hash is therefore stable across Puppet runs, *but* only insofar as the insertion order is stable. This function ensures hash keys are emitted in lexicographical order. Change-Id: I62605c2a23b3607dd8616c25d823ee341fb327c7 --- A modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb 1 file changed, 36 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/75/149775/1 diff --git a/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb b/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb new file mode 100644 index 0000000..3c7ed20 --- /dev/null +++ b/modules/wmflib/lib/puppet/parser/functions/ordered_yaml.rb @@ -0,0 +1,36 @@ +# == Function: ordered_yaml +# +# Serialize a hash into YAML with lexicographically sorted keys. +# +# Ruby 1.9+ hashes maintain insertion order. The serialized form +# of hash is therefore stable across Puppet runs only insofar as +# the insertion order is stable. This function ensures hash keys +# are emitted in lexicographical order. +# +require 'yaml' + +class Hash + alias_method :to_yaml_orig, :to_yaml + def to_yaml(options = {}) + Hash[sort].to_yaml_orig(options) + end +end + +module Puppet::Parser::Functions + newfunction( + :ordered_yaml, + :type => :rvalue, + :doc => <<-END + Serialize a hash into YAML with lexicographically sorted keys. + + Ruby 1.9+ hashes maintain insertion order. The serialized form + of hash is therefore stable across Puppet runs only insofar as + the insertion order is stable. This function ensures hash keys + are emitted in lexicographical order. + END + ) do |args| + newfunction(:ordered_yaml, :type => :rvalue) do |args| + fail 'ordered_yaml() requires a single argument' unless args.length == 1 + args.first.to_yaml + end +end -- To view, visit https://gerrit.wikimedia.org/r/149775 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62605c2a23b3607dd8616c25d823ee341fb327c7 Gerrit-PatchSet: 1 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits