Module: LibXML::XML::XQuery::Namespaces

Defined in:
lib/libxml/xquery/namespaces.rb

Overview

#

A component of ruby-xquery, mimicking XQuery in Ruby. #

#

Copyright © 2007-2008 Jens Wille #

#

Authors: #

Jens Wille <[email protected]>                                    #
                                                                        #

ruby-xquery is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. #

#

ruby-xquery is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. #

#

You should have received a copy of the GNU General Public License along # with ruby-xquery. If not, see <www.gnu.org/licenses/>. #

#

++

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/libxml/xquery/namespaces.rb', line 41

def self.included(base)
  base.const_set(:DEFAULT_NAMESPACES, [])

  # container for XML::Node's access to its document's namespaces
  base.instance_variable_set(
    :@namespaces, Hash.new(base.const_get(:DEFAULT_NAMESPACES))
  )

  class << base; attr_reader :namespaces; end

  # overwrite original methods
  instance_methods.each { |method|
    base.send(:define_method, method, instance_method(method))
  }
end

Instance Method Details

#namespacesObject



29
30
31
# File 'lib/libxml/xquery/namespaces.rb', line 29

def namespaces
  @namespaces ||= self.class::DEFAULT_NAMESPACES
end

#namespaces=(ns) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/libxml/xquery/namespaces.rb', line 33

def namespaces=(ns)
  if url
    @namespaces = self.class.namespaces[url] = ns
  else
    raise "can't set namespaces (document has no URL)"
  end
end