Skip to content

Commit

Permalink
Allow to pass already configured Nori instance and not mess Nori opti…
Browse files Browse the repository at this point in the history
…ons with Savon options
  • Loading branch information
ekzobrain authored and pcai committed Jul 15, 2024
1 parent a5bdcb9 commit 8e4101e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions lib/savon/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ def response_parser(parser)
@options[:response_parser] = parser
end

# Instruct Nori how to convert empty tags.
def empty_tag_value(empty_tag_value)
@options[:empty_tag_value] = empty_tag_value
# Pass already configured Nori instance.
def nori(nori)
@options[:nori] = nori
end

# Instruct Savon to create a multipart response if available.
Expand Down
23 changes: 9 additions & 14 deletions lib/savon/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,16 @@ def xml_namespaces
end

def nori
return @nori if @nori
return @locals[:nori] if @locals[:nori]

nori_options = {
:delete_namespace_attributes => @globals[:delete_namespace_attributes],
:strip_namespaces => @globals[:strip_namespaces],
:convert_tags_to => @globals[:convert_response_tags_to],
:convert_attributes_to => @globals[:convert_attributes_to],
:advanced_typecasting => @locals[:advanced_typecasting],
:parser => @locals[:response_parser],
:empty_tag_value => @locals[:empty_tag_value]
}

non_nil_nori_options = nori_options.reject { |_, value| value.nil? }
@nori = Nori.new(non_nil_nori_options)
@nori ||= Nori.new({
:delete_namespace_attributes => @globals[:delete_namespace_attributes],
:strip_namespaces => @globals[:strip_namespaces],
:convert_tags_to => @globals[:convert_response_tags_to],
:convert_attributes_to => @globals[:convert_attributes_to],
:advanced_typecasting => @locals[:advanced_typecasting],
:parser => @locals[:response_parser]
}.reject { |_, value| value.nil? })
end

end
end

0 comments on commit 8e4101e

Please sign in to comment.