-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple fixes for qualified message munger. (#676)
* Fixes handling of content! and attributes! * General cleanup.
- Loading branch information
Showing
2 changed files
with
82 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,49 +2,50 @@ | |
|
||
module Savon | ||
class QualifiedMessage | ||
|
||
def initialize(types, used_namespaces, key_converter) | ||
@types = types | ||
@types = types | ||
@used_namespaces = used_namespaces | ||
@key_converter = key_converter | ||
@key_converter = key_converter | ||
end | ||
|
||
def to_hash(hash, path) | ||
return hash unless hash | ||
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 key == :order! | ||
add_namespaces_to_values(value, path) | ||
newhash.merge(key => value) | ||
return unless hash | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return hash.map { |value| to_hash(value, path) } if hash.is_a?(Array) | ||
return hash.to_s unless hash.is_a?(Hash) | ||
|
||
hash.each_with_object({}) do |(key, value), newhash| | ||
case key | ||
when :order! | ||
newhash[key] = add_namespaces_to_values(value, path) | ||
when :attributes!, :content! | ||
newhash[key] = to_hash(value, path) | ||
else | ||
translated_key = Gyoku.xml_tag(key, :key_converter => @key_converter).to_s | ||
translated_key << "!" if key[-1] == "!" | ||
newpath = path + [translated_key] | ||
|
||
if @used_namespaces[newpath] | ||
newhash.merge( | ||
"#{@used_namespaces[newpath]}:#{translated_key}" => | ||
to_hash(value, @types[newpath] ? [@types[newpath]] : newpath) | ||
) | ||
if key.to_s =~ /!$/ | ||
newhash[key] = value | ||
else | ||
newhash.merge(translated_key => value) | ||
translated_key = translate_tag(key) | ||
newkey = add_namespaces_to_values(key, path).first | ||
newpath = path + [translated_key] | ||
newhash[newkey] = to_hash(value, newpath) | ||
This comment has been minimized.
Sorry, something went wrong.
fphilipe
|
||
end | ||
end | ||
newhash | ||
end | ||
end | ||
|
||
private | ||
|
||
def add_namespaces_to_values(values, path) | ||
values.collect! { |value| | ||
camelcased_value = Gyoku.xml_tag(value, :key_converter => @key_converter) | ||
namespace_path = path + [camelcased_value.to_s] | ||
namespace = @used_namespaces[namespace_path] | ||
"#{namespace.blank? ? '' : namespace + ":"}#{camelcased_value}" | ||
} | ||
def translate_tag(key) | ||
Gyoku.xml_tag(key, :key_converter => @key_converter).to_s | ||
end | ||
|
||
def add_namespaces_to_values(values, path) | ||
Array(values).collect do |value| | ||
translated_value = translate_tag(value) | ||
namespace_path = path + [translated_value] | ||
namespace = @used_namespaces[namespace_path] | ||
namespace.blank? ? value : "#{namespace}:#{translated_value}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It seems like the first line changed here could be the cause of #826. It seems like it might inadvertently change a false to a nil. WDYT?