module RGen::Ext::NavigationExtensions
This module is intended to be included in a class extending MMBase to plug-in additional functionalities to navigate the model
The methods use a parameter is used to make the method work on elements of the subtree which do not include this module
Public Instance Methods
all_children(of=self)
click to toggle source
# File lib/rgen/ext/navigation_extensions.rb, line 22 def all_children(of=self) arr = [] ecore = of.class.ecore ecore.eAllReferences.sort_by{|r| r.name}.select {|r| r.containment}.each do |ref| res = of.send(ref.name.to_sym) if ref.many res.each do |el| arr << el unless el==nil end elsif res!=nil arr << res end end arr end
all_children_deep(of=self)
click to toggle source
# File lib/rgen/ext/navigation_extensions.rb, line 38 def all_children_deep(of=self) arr = [] of.all_children.each do |c| arr << c c.all_children_deep.each do |cc| arr << cc end end arr end
root(of=self)
click to toggle source
Return the root of the model
# File lib/rgen/ext/navigation_extensions.rb, line 17 def root(of=self) return of unless of.eContainer root(of.eContainer) end
traverse(&op)
click to toggle source
The node itself and all the node in the sub-tree are passed to the given block
# File lib/rgen/ext/navigation_extensions.rb, line 51 def traverse(&op) op.call(self) all_children_deep.each do |c| op.call(c) end end