Sha256: 4d05db76e82a7244d6c5238021874b061ffcb162789bbea3578db7c8c657520a
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module EYAML class Util class << self def pretty_yaml(some_hash) some_hash.to_yaml.delete_prefix("---\n") end # This will look for any keys that starts with an underscore and duplicates that key-value pair # but without the starting underscore. # So {_a: "abab"} will become {_a: "abab", a: "abab"} # This so we can easilly access our unencrypted secrets without having to add an underscore def with_deep_deundescored_keys(hash) hash.each_with_object({}) do |(key, value), total| value = with_deep_deundescored_keys(value) if value.is_a?(Hash) if key.start_with?("_") deunderscored_key = key[1..] # We don't want to have an underscored and de-underscored key with the same name, so raise. This could be a security issue raise KeyError, "De-underscored key '#{key[1..]}' already exists." if total.key?(deunderscored_key) total[deunderscored_key] = value unless total.key?(deunderscored_key) end total[key] = value end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eyaml-0.4.4 | lib/eyaml/util.rb |
eyaml-0.4.3 | lib/eyaml/util.rb |