Skip to content

Commit

Permalink
Rename sorted_hash to sort_hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
fohara committed Nov 26, 2013
1 parent 6183211 commit 8d5ce18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/billy/resource_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions spec/lib/billy/resource_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8d5ce18

Please sign in to comment.