From 8d5ce18860adfbd0f687fea89dd436f91d46abfe Mon Sep 17 00:00:00 2001 From: Frank O'Hara Date: Tue, 26 Nov 2013 13:45:32 -0600 Subject: [PATCH] Rename sorted_hash to sort_hash. --- lib/billy/resource_utils.rb | 8 ++++---- spec/lib/billy/resource_utils_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/billy/resource_utils.rb b/lib/billy/resource_utils.rb index 0514d03..1d77b47 100644 --- a/lib/billy/resource_utils.rb +++ b/lib/billy/resource_utils.rb @@ -21,17 +21,17 @@ def json?(value) false end - def sorted_hash(hash, &block) + def sort_hash(hash, &block) Hash[ hash.each do |k,v| - hash[k] = sorted_hash(v, &block) if v.class == Hash - hash[k] = v.collect {|a| sorted_hash(a, &block)} if v.class == Array + hash[k] = sort_hash(v, &block) if v.class == Hash + hash[k] = v.collect {|a| sort_hash(a, &block)} if v.class == Array end.sort(&block) ] end def sorted_json(json_str) - sorted_hash(JSON.parse(json_str, symbolize_names: true)).to_json + sort_hash(JSON.parse(json_str, symbolize_names: true)).to_json end end end \ No newline at end of file diff --git a/spec/lib/billy/resource_utils_spec.rb b/spec/lib/billy/resource_utils_spec.rb index 22107cd..b37183f 100644 --- a/spec/lib/billy/resource_utils_spec.rb +++ b/spec/lib/billy/resource_utils_spec.rb @@ -9,12 +9,12 @@ let(:unsorted_hash_2_level) { helper.unsorted_hash_2_level } let(:unsorted_hash_3_level) { helper.unsorted_hash_3_level } - describe 'sorted_hash' do + describe 'sort_hash' do it 'sorts nested hashes 1 level deep' do - expect(sorted_hash(unsorted_hash_2_level)).to eq sorted_hash_2_level + expect(sort_hash(unsorted_hash_2_level)).to eq sorted_hash_2_level end it 'sorts nested hashes 2 levels deep' do - expect(sorted_hash(unsorted_hash_3_level)).to eq sorted_hash_3_level + expect(sort_hash(unsorted_hash_3_level)).to eq sorted_hash_3_level end end