Class: RouteTree

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_notebook/route.rb

Instance Method Summary collapse

Constructor Details

#initialize(_headNode) ⇒ RouteTree

Returns a new instance of RouteTree.



81
82
83
# File 'lib/rails_notebook/route.rb', line 81

def initialize( _headNode )
	@headNode = _headNode
end

Instance Method Details

#getRootObject



115
116
117
# File 'lib/rails_notebook/route.rb', line 115

def getRoot
	@headNode
end

#insertNode(_node) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rails_notebook/route.rb', line 85

def insertNode( _node )
	#Get route mapping and iteratively either walk the tree or insert a node at the correct position
	uri_mapping = ""
	thisNode = @headNode #always insert from the headNode

	_node.uriPattern.split("/").each do |uri|
           uri_mapping += uri + "/"
           if uri_mapping[0...-1] == _node.uriPattern || uri_mapping == _node.uriPattern # We are at node to insert or update
           	if thisNode.uriPattern == uri_mapping # Update the parameters to include details
           		thisNode.updateParams( _node.verb , _node.controller , _node.action ) 
           	elsif thisNode.hasRoute( uri_mapping )
           		thisNode.hasRoute( uri_mapping ).updateParams( _node.verb , _node.controller , _node.action )
           	else 
           		child = RouteNode.new( uri_mapping , _node.verb , _node.controller , _node.action, uri )
           		thisNode.insertChild( child )
           	end
           elsif thisNode.hasRoute( uri_mapping ) # node exists so walk the tree
           	thisNode = thisNode.hasRoute( uri_mapping )
           elsif thisNode.uriPattern == uri_mapping # already there so do nothing
           	#thisNode.updateParams( _node.verb , _node.controller , _node.action )
           else
           	child = RouteNode.new( uri_mapping , nil, nil , nil, uri )
           	thisNode.insertChild( child )
           	thisNode = child
           end
       end
end

#printTreeObject



118
119
120
# File 'lib/rails_notebook/route.rb', line 118

def printTree
	@headNode.printNode
end

#removeNode(_node) ⇒ Object



112
113
114
# File 'lib/rails_notebook/route.rb', line 112

def removeNode( _node )
	puts "removing node"
end