Module: XML::XXPath::Accessors::UnspecifiednessSupport

Included in:
Attribute
Defined in:
lib/xml/rexml_ext.rb

Overview

we need a boolean “unspecified?” attribute for XML nodes – paths like “*” oder (somewhen) “foo|bar” create “unspecified” nodes that the user must then “specify” by setting their text etc. (or manually setting unspecified=false)

This is mixed into the REXML::Element and XML::XXPath::Accessors::Attribute classes.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xml/rexml_ext.rb', line 28

def self.append_features(base)
  return if base.included_modules.include? self # avoid aliasing methods more than once
                                                # (would lead to infinite recursion)
  super
  base.module_eval "    alias_method :_text_orig, :text\n    alias_method :_textis_orig, :text=\n    def text\n      # we're suffering from the \"fragile base class\"\n      # phenomenon here -- we don't know whether the\n      # implementation of the class we get mixed into always\n      # calls text (instead of just accessing @text or so)\n      if unspecified?\n        \"[UNSPECIFIED]\"\n      else\n        _text_orig\n      end\n    end\n    def text=(x)\n      _textis_orig(x)\n      self.unspecified=false\n    end\n\n    alias_method :_nameis_orig, :name=\n    def name=(x)\n      _nameis_orig(x)\n      self.unspecified=false\n    end\n  EOS\nend\n"

Instance Method Details

#unspecified=(x) ⇒ Object



24
25
26
# File 'lib/xml/rexml_ext.rb', line 24

def unspecified=(x)
  @xml_xpath_unspecified = x
end

#unspecified?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/xml/rexml_ext.rb', line 20

def unspecified?
  @xml_xpath_unspecified ||= false
end