Class: OM::XML::NamedTermProxy
- Inherits:
-
Object
- Object
- OM::XML::NamedTermProxy
- Includes:
- TreeNode
- Defined in:
- lib/om/xml/named_term_proxy.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#proxy_pointer ⇒ Object
Returns the value of attribute proxy_pointer.
-
#terminology ⇒ Object
Returns the value of attribute terminology.
Attributes included from TreeNode
Instance Method Summary collapse
-
#generate_xpath_queries! ⇒ Object
do nothing – this is to prevent errors when the parent term calls generate_xpath_queries! on its children.
-
#index_as ⇒ Object
Always co-erce :index_as attributes into an Array.
-
#initialize(name, proxy_pointer, terminology, opts = {}) ⇒ NamedTermProxy
constructor
Creates a Named Proxy that points to another term in the Terminology.
-
#is_root_term? ⇒ Boolean
A proxy term can never serve as the root term of a Terminology.
-
#method_missing(method, *args, &block) ⇒ Object
Any unknown method calls will be proxied to the proxied term.
- #proxied_term ⇒ Object
Methods included from TreeNode
#add_child, #parent, #retrieve_child, #set_parent
Constructor Details
#initialize(name, proxy_pointer, terminology, opts = {}) ⇒ NamedTermProxy
Creates a Named Proxy that points to another term in the Terminology. Unlike regular terms, NamedTermProxy requires you to provide a reference to the containing Terminology. This is to ensure that it will always be able to look up the term that it’s referencing.
14 15 16 17 18 19 20 21 22 |
# File 'lib/om/xml/named_term_proxy.rb', line 14 def initialize(name, proxy_pointer, terminology, opts={}) opts = {:namespace_prefix=>"oxns", :ancestors=>[], :children=>{}}.merge(opts) [:children, :ancestors, :index_as].each do |accessor_name| instance_variable_set("@#{accessor_name}", opts.fetch(accessor_name, nil) ) end @terminology = terminology @name = name @proxy_pointer = proxy_pointer end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Any unknown method calls will be proxied to the proxied term
59 60 61 |
# File 'lib/om/xml/named_term_proxy.rb', line 59 def method_missing method, *args, &block return self.proxied_term.send(method, *args) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/om/xml/named_term_proxy.rb', line 3 def name @name end |
#proxy_pointer ⇒ Object
Returns the value of attribute proxy_pointer.
3 4 5 |
# File 'lib/om/xml/named_term_proxy.rb', line 3 def proxy_pointer @proxy_pointer end |
#terminology ⇒ Object
Returns the value of attribute terminology.
3 4 5 |
# File 'lib/om/xml/named_term_proxy.rb', line 3 def terminology @terminology end |
Instance Method Details
#generate_xpath_queries! ⇒ Object
do nothing – this is to prevent errors when the parent term calls generate_xpath_queries! on its children
38 39 40 |
# File 'lib/om/xml/named_term_proxy.rb', line 38 def generate_xpath_queries! # do nothing end |
#index_as ⇒ Object
Always co-erce :index_as attributes into an Array
50 51 52 53 54 55 56 |
# File 'lib/om/xml/named_term_proxy.rb', line 50 def index_as if @index_as Array(@index_as) else self.proxied_term.index_as end end |
#is_root_term? ⇒ Boolean
A proxy term can never serve as the root term of a Terminology. Explicitly setting is_root_term? to return false to support proxies that are at the root of the Terminology but aren’t the root term.
44 45 46 |
# File 'lib/om/xml/named_term_proxy.rb', line 44 def is_root_term? return false end |
#proxied_term ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/om/xml/named_term_proxy.rb', line 24 def proxied_term if self.parent.nil? pt = self.terminology.retrieve_term(*self.proxy_pointer) else pt = self.parent.retrieve_term(*self.proxy_pointer) end if pt.nil? raise OM::XML::Terminology::BadPointerError, "The #{name} proxy term points to #{proxy_pointer.inspect} but that term doesn't exist." else return pt end end |