Parent

Class Index [+]

Quicksearch

Ramaze::AppGraph

The AppGraph class can be used to generate a graph of all the URLs mapped in a Ramaze application and saves this graph as an image.

In order to generate a graph of your application all you need to do is the following:

    require 'ramaze/app_graph'

    graph = Ramaze::AppGraph.new graph.generate graph.show

Once this code is executed you can find the .dot and PNG files in the root directory of your application.

@author Michael Fellinger

Public Class Methods

new() click to toggle source

Creates a new instance of the class.

@author Michael Fellinger

    # File lib/ramaze/app_graph.rb, line 26
26:     def initialize
27:       @out = Set.new
28:     end

Public Instance Methods

connect(hash) click to toggle source

Connects various elements in the graph to each other.

@author Michael Fellinger

    # File lib/ramaze/app_graph.rb, line 69
69:     def connect(hash)
70:       hash.each do |from, to|
71:         @out << ("  %p -> %p;" % [from.to_s, to.to_s])
72:       end
73:     end
generate() click to toggle source

Generates the graph based on all the current routes. The graph is saved in the application directory.

@author Michael Fellinger

    # File lib/ramaze/app_graph.rb, line 36
36:     def generate
37:       Ramaze::AppMap.to_hash.each do |location, app|
38:         connect(location => app.name)
39: 
40:         app.url_map.to_hash.each do |c_location, c_node|
41:           connect(app.name => c_node)
42:           connect(c_node.mapping => c_node)
43: 
44:           c_node.update_template_mappings
45:           c_node.view_templates.each do |wish, mapping|
46:             mapping.each do |action_name, template|
47:               action_path = File.join(c_node.mapping, action_name)
48:               connect(c_node => action_path, action_path => template)
49:             end
50:           end
51: 
52:           c_node.update_method_arities
53:           c_node.method_arities.each do |method, arity|
54:             action_path = File.join(c_node.mapping, method.to_s)
55:             connect(
56:               action_path => "#{c_node}##{method}[#{arity}]",
57:               c_node      => action_path
58:             )
59:           end
60:         end
61:       end
62:     end
show() click to toggle source

Generates a PNG file based on the .dot file.

@author Michael Fellinger

     # File lib/ramaze/app_graph.rb, line 93
 93:     def show
 94:       write_dot
 95:       options = {
 96:         'rankdir' => 'LR',
 97:         'splines' => 'true',
 98:         'overlap' => 'false',
 99:       }
100:       args = options.map{|k,v| "-G#{k}=#{v}" }
101:       system("dot -O -Tpng #{args.join(' ')} graph.dot")
102:       system('feh graph.dot.png')
103:     end
write_dot() click to toggle source

Writes the dot file containing the graph data.

@author Michael Fellinger

    # File lib/ramaze/app_graph.rb, line 80
80:     def write_dot
81:       File.open('graph.dot', 'w+') do |dot|
82:         dot.puts 'digraph appmap {'
83:         dot.puts(*@out)
84:         dot.puts '}'
85:       end
86:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.