Commit de43390

mo <mo.khan@gmail.com>
2018-02-26 02:23:52
remove usages of Xml::Kit::Document.
1 parent 6139e55
lib/saml/kit/composite_metadata.rb
@@ -14,7 +14,7 @@ module Saml
 
       def services(type)
         xpath = map { |x| "//md:EntityDescriptor/md:#{x.name}/md:#{type}" }.join('|')
-        document.find_all(xpath).map do |item|
+        search(xpath).map do |item|
           binding = item.attribute('Binding').value
           location = item.attribute('Location').value
           Saml::Kit::Bindings.create_for(binding, location)
lib/saml/kit/identity_provider_metadata.rb
@@ -38,7 +38,7 @@ module Saml
       # Returns the IDPSSODescriptor/@WantAuthnRequestsSigned attribute.
       def want_authn_requests_signed
         xpath = "/md:EntityDescriptor/md:#{name}"
-        attribute = document.find_by(xpath).attribute('WantAuthnRequestsSigned')
+        attribute = at_xpath(xpath).attribute('WantAuthnRequestsSigned')
         return true if attribute.nil?
         attribute.text.casecmp('true').zero?
       end
@@ -57,7 +57,7 @@ module Saml
 
       # Returns each of the Attributes in the metadata.
       def attributes
-        document.find_all("/md:EntityDescriptor/md:#{name}/saml:Attribute").map do |item|
+        search("/md:EntityDescriptor/md:#{name}/saml:Attribute").map do |item|
           {
             format: item.attribute('NameFormat').try(:value),
             name: item.attribute('Name').value,
lib/saml/kit/metadata.rb
@@ -159,7 +159,7 @@ module Saml
       #
       # @param pretty [Symbol] true to return a human friendly version of the XML.
       def to_xml(pretty: false)
-        document.to_xml(pretty: pretty)
+        pretty ? to_nokogiri.to_xml(indent: 2) : @xml
       end
 
       # Returns the XML document as a [String].
@@ -210,25 +210,21 @@ module Saml
 
       attr_reader :xml
 
-      def document
-        @document ||= ::Xml::Kit::Document.new(xml, namespaces: NAMESPACES)
-      end
-
       # @!visibility private
       def to_nokogiri
         @nokogiri ||= Nokogiri::XML(xml)
       end
 
       def at_xpath(xpath)
-        document.find_by(xpath)
+        to_nokogiri.at_xpath(xpath, NAMESPACES)
       end
 
       def search(xpath)
-        document.find_all(xpath)
+        to_nokogiri.search(xpath, NAMESPACES)
       end
 
       def metadata
-        document.find_by("/md:EntityDescriptor/md:#{name}").present?
+        at_xpath("/md:EntityDescriptor/md:#{name}").present?
       end
 
       def must_contain_descriptor
lib/saml/kit/service_provider_metadata.rb
@@ -20,7 +20,7 @@ module Saml
 
       # Returns true when the metadata demands that Assertions must be signed.
       def want_assertions_signed
-        attribute = document.find_by("/md:EntityDescriptor/md:#{name}").attribute('WantAssertionsSigned')
+        attribute = at_xpath("/md:EntityDescriptor/md:#{name}").attribute('WantAssertionsSigned')
         return true if attribute.nil?
         attribute.text.casecmp('true').zero?
       end