Module: ConDuxml::Link
- Includes:
- Instance
- Defined in:
- lib/con_duxml/link.rb
Overview
links are effectively aliases for an XML node that can exist anywhere outside of that node they confer referencing scope, namespace, and notifications of content changes anything contained by a link element is then dynamically linked to the target this is useful for designs where one element’s state depends on another’s or where it’s important to track a target that may not be in a fixed location
Instance Method Summary collapse
-
#instantiate(&block) ⇒ Array
Nodes to replace this link - children by default.
- #ref=(target) ⇒ Object
-
#strict?(bool = nil) ⇒ true, false
Returns current value (true by default).
-
#update(type, *args) ⇒ Object
TODO rewrite this!!! at most primitive, updates need to happen when link targets split/merge or are removed.
- #valid? ⇒ Boolean
Methods included from Instance
Instance Method Details
#instantiate(&block) ⇒ Array
Returns nodes to replace this link - children by default.
29 30 31 32 |
# File 'lib/con_duxml/link.rb', line 29 def instantiate(&block) resolve_ref.add_observer(self) block_given? ? yield(nodes.each) : nodes end |
#ref=(target) ⇒ Object
22 23 24 25 |
# File 'lib/con_duxml/link.rb', line 22 def ref=(target) target.extend Linkable @ref = target end |
#strict?(bool = nil) ⇒ true, false
Returns current value (true by default)
36 37 38 |
# File 'lib/con_duxml/link.rb', line 36 def strict?(bool=nil) bool.nil? ? @strict_or_false ||= true : @strict_or_false = bool end |
#update(type, *args) ⇒ Object
TODO rewrite this!!! at most primitive, updates need to happen when link targets split/merge or are removed
43 44 45 46 47 48 49 50 |
# File 'lib/con_duxml/link.rb', line 43 def update(type, *args) change_class = Duxml::const_get "#{type.to_s}Class".to_sym change_comp = change_class.new *args @nodes.unshift change_comp changed notify_observers(change_comp) unless change_comp.respond_to?(:error?) raise(Exception, change_comp.description) if strict? && type == :QualifyError end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/con_duxml/link.rb', line 18 def valid? !resolve_ref.nil? end |