From 8e4101ee94879502bf3c1983802f62f73ee29de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=85=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=94=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 22 Feb 2021 13:39:05 +0200 Subject: [PATCH] Allow to pass already configured Nori instance and not mess Nori options with Savon options --- lib/savon/options.rb | 6 +++--- lib/savon/response.rb | 23 +++++++++-------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/savon/options.rb b/lib/savon/options.rb index 2e44acc7..a3848b93 100644 --- a/lib/savon/options.rb +++ b/lib/savon/options.rb @@ -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. diff --git a/lib/savon/response.rb b/lib/savon/response.rb index 6bcd78f2..e148182b 100644 --- a/lib/savon/response.rb +++ b/lib/savon/response.rb @@ -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