Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/savon/qualified_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def to_hash(hash, path)
return hash.map { |value| to_hash(value, path) } if hash.kind_of?(Array)
return hash.to_s unless hash.kind_of? Hash

hash.inject({}) do |newhash, (key, value)|
if hash[:order!] == :use_schema || @order_with_schema
@order_with_schema = true
ordered_keys = @used_namespaces.select { |t| t.first == path.first && t.length == 2 }.keys.collect { |k| k.last }
hash[:order!] = ordered_keys
end

result = hash.inject({}) do |newhash, (key, value)|
if key == :order!
add_namespaces_to_values(value, path)
newhash.merge(key => value)
Expand All @@ -33,6 +39,8 @@ def to_hash(hash, path)
end
end
end

update_order_keys(result)
end

private
Expand All @@ -46,5 +54,13 @@ def add_namespaces_to_values(values, path)
}
end

def update_order_keys(hash)
return hash unless @order_with_schema

order_keys = hash.delete(:order!)
present_order_keys = order_keys & hash.keys
hash[:order!] = present_order_keys + (hash.keys - present_order_keys)
hash
end
end
end