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.
This commit is contained in:
Yorick Peterse 2014-08-14 23:12:33 +02:00
parent d34e4697de
commit d0092b434d
3 changed files with 2 additions and 31 deletions

View File

@ -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.
#

View File

@ -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

View File

@ -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')