From d0092b434d0808c44b15cabc953058dcc71e6868 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 14 Aug 2014 23:12:33 +0200 Subject: [PATCH] Removed Document#available_namespaces. Namespaces aren't scoped per document but instead per element, thus this method doesn't make that much sense. This also fixes the remaining, failing XPath test. --- lib/oga/xml/document.rb | 17 ----------------- lib/oga/xpath/evaluator.rb | 2 ++ spec/oga/xml/document_spec.rb | 14 -------------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/lib/oga/xml/document.rb b/lib/oga/xml/document.rb index 9a995ee..ae82630 100644 --- a/lib/oga/xml/document.rb +++ b/lib/oga/xml/document.rb @@ -89,23 +89,6 @@ module Oga end end - ## - # Returns the available namespaces. These namespaces are retrieved from - # the first element in the document. - # - # @see [Oga::XML::Element#available_namespaces] - # - def available_namespaces - children.each do |child| - # There's no guarantee that the first node is *always* an element - # node. - return child.available_namespaces if child.is_a?(Element) - end - - # In case the document is empty. - return {} - end - ## # Converts the document and its child nodes to XML. # diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 0ba6968..657df79 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -411,6 +411,8 @@ module Oga name = ast_node.children[1] context.each do |context_node| + next unless context_node.respond_to?(:available_namespaces) + context_node.available_namespaces.each do |_, namespace| if namespace.name == name or name == '*' nodes << namespace diff --git a/spec/oga/xml/document_spec.rb b/spec/oga/xml/document_spec.rb index e475b85..5c68e5c 100644 --- a/spec/oga/xml/document_spec.rb +++ b/spec/oga/xml/document_spec.rb @@ -71,20 +71,6 @@ describe Oga::XML::Document do end end - context '#available_namespaces' do - example 'return an empty Hash by default' do - described_class.new.available_namespaces.should be_empty - end - - example 'return the namespaces of the first element' do - namespace = Oga::XML::Namespace.new(:name => 'x') - element = Oga::XML::Element.new(:namespaces => {'x' => namespace}) - document = described_class.new(:children => [element]) - - document.available_namespaces['x'].should == namespace - end - end - context '#to_xml' do before do child = Oga::XML::Comment.new(:text => 'foo')