Class: AppGraph
Overview
require ‘ramaze/contrib/app_graph’
graph = AppGraph.new graph.generate graph.show
Instance Method Summary collapse
- #connect(hash) ⇒ Object
- #generate ⇒ Object
-
#initialize ⇒ AppGraph
constructor
A new instance of AppGraph.
- #show ⇒ Object
- #write_dot ⇒ Object
Constructor Details
#initialize ⇒ AppGraph
Returns a new instance of AppGraph.
10 11 12 |
# File 'lib/ramaze/contrib/app_graph.rb', line 10 def initialize @out = Set.new end |
Instance Method Details
#connect(hash) ⇒ Object
39 40 41 42 43 |
# File 'lib/ramaze/contrib/app_graph.rb', line 39 def connect(hash) hash.each do |from, to| @out << (" %p -> %p;" % [from.to_s, to.to_s]) end end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ramaze/contrib/app_graph.rb', line 14 def generate Ramaze::AppMap.to_hash.each do |location, app| connect(location => app.name) app.url_map.to_hash.each do |c_location, c_node| connect(app.name => c_node) connect(c_node.mapping => c_node) c_node.update_template_mappings c_node.view_templates.each do |wish, mapping| mapping.each do |action_name, template| action_path = File.join(c_node.mapping, action_name) connect(c_node => action_path, action_path => template) end end c_node.update_method_arities c_node.method_arities.each do |method, arity| action_path = File.join(c_node.mapping, method.to_s) connect(action_path => "#{c_node}##{method}[#{arity}]", c_node => action_path) end end end end |
#show ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ramaze/contrib/app_graph.rb', line 53 def show write_dot = { 'rankdir' => 'LR', 'splines' => 'true', 'overlap' => 'false', } args = .map{|k,v| "-G#{k}=#{v}" } system("dot -O -Tpng #{args.join(' ')} graph.dot") system('feh graph.dot.png') end |
#write_dot ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/ramaze/contrib/app_graph.rb', line 45 def write_dot File.open('graph.dot', 'w+') do |dot| dot.puts 'digraph appmap {' dot.puts(*@out) dot.puts '}' end end |