Module: KnifeUploader::Utils
- Defined in:
- lib/chef/knife/uploader_base.rb
Class Method Summary collapse
- .json_with_sorted_keys(h) ⇒ Object
- .recursive_sort_hash_keys(obj) ⇒ Object
- .sort_hash_keys(h) ⇒ Object
Class Method Details
.json_with_sorted_keys(h) ⇒ Object
89 90 91 |
# File 'lib/chef/knife/uploader_base.rb', line 89 def json_with_sorted_keys(h) JSON.pretty_generate(recursive_sort_hash_keys(h)) + "\n" end |
.recursive_sort_hash_keys(obj) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/chef/knife/uploader_base.rb', line 79 def recursive_sort_hash_keys(obj) if [Hash, Hashie::Mash, VariaModel::Attributes].include?(obj.class) Hash[*obj.sort.map {|k, v| [k, recursive_sort_hash_keys(v)] }.flatten(1)] elsif obj.instance_of?(Array) obj.map {|element| recursive_sort_hash_keys(element) } else obj end end |
.sort_hash_keys(h) ⇒ Object
75 76 77 |
# File 'lib/chef/knife/uploader_base.rb', line 75 def sort_hash_keys(h) Hash[*h.sort.flatten(1)] end |