Parent

Included Modules

Class Index [+]

Quicksearch

Webgen::Tree

Represents a tree of nodes.

Attributes

dummy_root[R]

The dummy root. This is the default node that gets created when the Tree is created sothat the real root node can be treated like any other node. It has only one child, namely the real root node of the tree.

node_access[R]

Direct access to the hashes for node resolving. Only use this for reading purposes! If you just want to get a specific node for an alcn/acn/output path, use # instead.

node_info[R]

The hash containing processing information for each node. This is normally not accessed directly but via the Node#node_info method.

Public Class Methods

new() click to toggle source

Create a new Tree object.

    # File lib/webgen/tree.rb, line 27
27:     def initialize
28:       @node_access = {:alcn => {}, :acn => {}, :path => {}}
29:       @node_info = {}
30:       @dummy_root = Node.new(self, '', '')
31:     end

Public Instance Methods

[](path, type = :alcn) click to toggle source
Alias for: node
delete_node(node_or_alcn) click to toggle source

Delete the node identified by node_or_alcn and all of its children from the tree.

The message :before_node_deleted is sent with the to-be-deleted node before this node is actually deleted from the tree.

    # File lib/webgen/tree.rb, line 73
73:     def delete_node(node_or_alcn)
74:       n = node_or_alcn.kind_of?(Node) ? node_or_alcn : @node_access[:alcn][node_or_alcn]
75:       return if n.nil? || n == @dummy_root
76: 
77:       n.children.dup.each {|child| delete_node(child)}
78: 
79:       website.blackboard.dispatch_msg(:before_node_deleted, n)
80:       n.parent.children.delete(n)
81:       @node_access[:alcn].delete(n.alcn)
82:       @node_access[:acn][n.acn].delete(n)
83:       @node_access[:path].delete(n.path)
84: 
85:       node_info.delete(n.alcn)
86:     end
node(path, type = :alcn) click to toggle source

Access a node via a path of a specific type. If type is alcn then path has to be an absolute localized canonical name, if type is acn then path has to be an absolute canonical name and if type is path then path needs to be an output path.

Returns the requested Node or nil if such a node does not exist.

    # File lib/webgen/tree.rb, line 43
43:     def node(path, type = :alcn)
44:       (type == :acn ? @node_access[type][path] && @node_access[type][path].first : @node_access[type][path])
45:     end
Also aliased as: []
register_node(node) click to toggle source

A utility method called by Node#initialize. This method should not be used directly!

    # File lib/webgen/tree.rb, line 49
49:     def register_node(node)
50:       if @node_access[:alcn].has_key?(node.alcn)
51:         raise "Can't have two nodes with same absolute lcn: #{node}"
52:       else
53:         @node_access[:alcn][node.alcn] = node
54:       end
55:       (@node_access[:acn][node.acn] ||= []) << node
56:       register_path(node)
57:     end
register_path(node) click to toggle source

A utility method called by Node#reinit. This method should not be used directly!

    # File lib/webgen/tree.rb, line 60
60:     def register_path(node)
61:       return if node['no_output']
62:       if @node_access[:path].has_key?(node.path)
63:         raise "Can't have two nodes with same output path: #{node.path}"
64:       else
65:         @node_access[:path][node.path] = node
66:       end
67:     end
root() click to toggle source

The real root node of the tree.

    # File lib/webgen/tree.rb, line 34
34:     def root
35:       @dummy_root.children.first
36:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.