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
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
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
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.