class Rexport::TreeNode
A basic tree for building up ActiveRecord find :include parameters
Attributes
children[RW]
name[RW]
Public Class Methods
new(name, *names)
click to toggle source
Initialize a tree node setting name and adding a child if one was passed
# File lib/rexport/tree_node.rb, line 9 def initialize(name, *names) self.name = name self.children = [] add_child(names) end
Public Instance Methods
add_child(*names)
click to toggle source
Add one or more children to the tree
# File lib/rexport/tree_node.rb, line 16 def add_child(*names) names.flatten! return unless (name = names.shift) node = children.find { |c| c.name == name } node ? node.add_child(names) : (children << TreeNode.new(name, names)) end
build_include()
click to toggle source
Return the include parameters for a child
# File lib/rexport/tree_node.rb, line 35 def build_include leaf_node? ? name.to_sym : { name.to_sym => children.map(&:build_include) } end
to_a()
click to toggle source
Return an array representation of the tree
# File lib/rexport/tree_node.rb, line 25 def to_a [name, children.map(&:to_a)] end
to_include()
click to toggle source
Return a :include comptatible statement from the tree
# File lib/rexport/tree_node.rb, line 30 def to_include children.map(&:build_include) end
Private Instance Methods
leaf_node?()
click to toggle source
# File lib/rexport/tree_node.rb, line 41 def leaf_node? children.blank? end