railroad 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ Version 0.4.0 (apr 25 2007)
2
+ - Draw inheritance edges in reverse way
3
+ (from superclass to subclass, with an arrow in the tail)
4
+ This improves how 'dot' renders the graph
5
+ - By default, don't draw transitive inherited associations
6
+ - Added --transitive flag to draw transitive inherited associations
7
+ - Added --exclude flag for ommiting classes (this may help to produce
8
+ diagrams for applications with broken classes)
9
+
10
+
1
11
  Version 0.3.4 (apr 12 2007)
2
12
  - Add support for model abstract classes.
3
13
  (don't try to get content columns, bug #10033)
data/README CHANGED
@@ -18,6 +18,9 @@ controller diagrams are best processed using neato.
18
18
  Common options:
19
19
  -b, --brief Generate compact diagram
20
20
  (no attributes nor methods)
21
+ -e, --exclude file1[,fileN] Exclude files
22
+ (relative path to 'app/models/' or
23
+ 'app/controllers/')
21
24
  -i, --inheritance Include inheritance relations
22
25
  -l, --label Add a label with diagram information
23
26
  (type, date, migration, version)
@@ -31,6 +34,8 @@ Models diagram options:
31
34
  --hide-types Hide attributes type
32
35
  -j, --join Concentrate edges
33
36
  -m, --modules Include modules
37
+ -t, --transitive Include transitive associations
38
+ (through inheritance)
34
39
 
35
40
  Controllers diagram options:
36
41
  --hide-public Hide public methods
@@ -82,12 +87,36 @@ the following:
82
87
  Important: There is a bug in Graphviz tools when generating SVG files that
83
88
  cause a text overflow. You can solve this problem editing (with a text
84
89
  editor, not a graphical SVG editor) the file and replacing around line 12
85
- "font-size:14.00;" by "font-size:11.00;".
90
+ "font-size:14.00;" by "font-size:11.00;", or by issuing the following command
91
+ (see "man sed"):
92
+
93
+ sed -i 's/font-size:14.00/font-size:11.00/g' file.svg
86
94
 
87
95
  Note: For viewing and editing SVG there is an excellent opensource tool
88
96
  called Inkscape (similar to Adobe Illustrator. For DOT processing you can
89
97
  also use Omnigraffle (on Mac OS X).
90
98
 
99
+ = RailRoad as a rake task
100
+
101
+ (Thanks to Thomas Ritz, http://www.galaxy-ritz.de ,for the code.)
102
+
103
+ In your Rails application, put the following rake tasks into 'lib/task/diagrams.rake':
104
+
105
+ namespace :doc do
106
+ namespace :diagram do
107
+ task :models do
108
+ sh "railroad -i -l -a -m -M | dot -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/models.svg"
109
+ end
110
+
111
+ task :controllers do
112
+ sh "railroad -i -l -C | neato -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/controllers.svg"
113
+ end
114
+ end
115
+
116
+ task :diagrams => %w(diagram:models diagram:controllers)
117
+ end
118
+
119
+ Then, 'rake doc:diagrams' produces 'doc/models.svg' and 'doc/controllers.svg'.
91
120
 
92
121
  = Requirements
93
122
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  APP_NAME = "railroad"
18
18
  APP_HUMAN_NAME = "RailRoad"
19
- APP_VERSION = [0,3,4]
19
+ APP_VERSION = [0,4,0]
20
20
  COPYRIGHT = "Copyright (C) 2007 Javier Smaldone"
21
21
 
22
22
  require 'railroad/options_struct'
@@ -10,6 +10,7 @@ require 'railroad/app_diagram'
10
10
  class ControllersDiagram < AppDiagram
11
11
 
12
12
  def initialize(options)
13
+ options.exclude.map! {|e| e = "app/controllers/" + e}
13
14
  super options
14
15
  @graph.diagram_type = 'Controllers'
15
16
  end
@@ -18,7 +19,7 @@ class ControllersDiagram < AppDiagram
18
19
  def generate
19
20
  STDERR.print "Generating controllers diagram\n" if @options.verbose
20
21
 
21
- files = Dir.glob("app/controllers/**/*_controller.rb")
22
+ files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
22
23
  files << 'app/controllers/application.rb'
23
24
  files.each do |f|
24
25
  class_name = extract_class_name(f)
@@ -36,7 +37,8 @@ class ControllersDiagram < AppDiagram
36
37
  disable_stdout
37
38
  # ApplicationController must be loaded first
38
39
  require "app/controllers/application.rb"
39
- Dir.glob("app/controllers/**/*_controller.rb") {|c| require c }
40
+ files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
41
+ files.each {|c| require c }
40
42
  enable_stdout
41
43
  rescue LoadError
42
44
  enable_stdout
@@ -74,7 +76,8 @@ class ControllersDiagram < AppDiagram
74
76
  # Generate the inheritance edge (only for ApplicationControllers)
75
77
  if @options.inheritance &&
76
78
  (ApplicationController.subclasses.include? current_class.name)
77
- @graph.add_edge ['is-a', current_class.name, current_class.superclass.name]
79
+ # REVERSE INHERITANCE (CHECK)
80
+ @graph.add_edge ['is-a', current_class.superclass.name, current_class.name]
78
81
  end
79
82
  end # process_class
80
83
 
@@ -106,7 +106,9 @@ class DiagramGraph
106
106
  when 'many-many'
107
107
  options += 'taillabel="n", headlabel="n", arrowtail="normal"'
108
108
  when 'is-a'
109
- options += 'arrowhead="onormal"'
109
+ # REVERSE INHERITANCE (CHECK)
110
+ # options += 'arrowhead="onormal"'
111
+ options += 'arrowhead="none", arrowtail="onormal"'
110
112
  end
111
113
  return "\t#{quote(from)} -> #{quote(to)} [#{options}]\n"
112
114
  end # dot_edge
@@ -10,6 +10,7 @@ require 'railroad/app_diagram'
10
10
  class ModelsDiagram < AppDiagram
11
11
 
12
12
  def initialize(options)
13
+ options.exclude.map! {|e| e = "app/models/" + e}
13
14
  super options
14
15
  @graph.diagram_type = 'Models'
15
16
  # Processed habtm associations
@@ -19,7 +20,7 @@ class ModelsDiagram < AppDiagram
19
20
  # Process model files
20
21
  def generate
21
22
  STDERR.print "Generating models diagram\n" if @options.verbose
22
- files = Dir.glob("app/models/**/*.rb")
23
+ files = Dir.glob("app/models/**/*.rb") - @options.exclude
23
24
  files.each do |f|
24
25
  process_class extract_class_name(f).constantize
25
26
  end
@@ -31,7 +32,8 @@ class ModelsDiagram < AppDiagram
31
32
  def load_classes
32
33
  begin
33
34
  disable_stdout
34
- Dir.glob("app/models/**/*.rb") {|m| require m }
35
+ files = Dir.glob("app/models/**/*.rb") - @options.exclude
36
+ files.each {|m| require m }
35
37
  enable_stdout
36
38
  rescue LoadError
37
39
  enable_stdout
@@ -64,7 +66,15 @@ class ModelsDiagram < AppDiagram
64
66
  @graph.add_node [node_type, current_class.name, node_attribs]
65
67
  generated = true
66
68
  # Process class associations
67
- current_class.reflect_on_all_associations.each do |a|
69
+ associations = current_class.reflect_on_all_associations
70
+ if @options.inheritance && ! @options.transitive
71
+ superclass_associations = current_class.superclass.reflect_on_all_associations
72
+
73
+ associations = associations.select{|a| ! superclass_associations.include? a}
74
+ # This doesn't works!
75
+ # associations -= current_class.superclass.reflect_on_all_associations
76
+ end
77
+ associations.each do |a|
68
78
  process_association current_class.name, a
69
79
  end
70
80
  elsif @options.all && (current_class.is_a? Class)
@@ -80,7 +90,8 @@ class ModelsDiagram < AppDiagram
80
90
  if @options.inheritance && generated &&
81
91
  (current_class.superclass != ActiveRecord::Base) &&
82
92
  (current_class.superclass != Object)
83
- @graph.add_edge ['is-a', current_class.name, current_class.superclass.name]
93
+ # REVERSE INHERITANCE (CHECK)
94
+ @graph.add_edge ['is-a', current_class.superclass.name, current_class.name]
84
95
  end
85
96
 
86
97
  end # process_class
@@ -14,6 +14,7 @@ class OptionsStruct < OpenStruct
14
14
  def initialize
15
15
  init_options = { :all => false,
16
16
  :brief => false,
17
+ :exclude => [],
17
18
  :inheritance => false,
18
19
  :join => false,
19
20
  :label => false,
@@ -22,7 +23,9 @@ class OptionsStruct < OpenStruct
22
23
  :hide_public => false,
23
24
  :hide_protected => false,
24
25
  :hide_private => false,
26
+ :transitive => false,
25
27
  :verbose => false,
28
+ # :xmi => false,
26
29
  :command => '' }
27
30
  super(init_options)
28
31
  end # initialize
@@ -36,6 +39,10 @@ class OptionsStruct < OpenStruct
36
39
  " (no attributes nor methods)") do |b|
37
40
  self.brief = b
38
41
  end
42
+ opts.on("-e", "--exclude file1[,fileN]", Array, "Exclude files",
43
+ " (relative path to 'app/models/' or", " 'app/controllers/')") do |list|
44
+ self.exclude = list
45
+ end
39
46
  opts.on("-i", "--inheritance", "Include inheritance relations") do |i|
40
47
  self.inheritance = i
41
48
  end
@@ -50,6 +57,11 @@ class OptionsStruct < OpenStruct
50
57
  " (produce messages to STDOUT)") do |v|
51
58
  self.verbose = v
52
59
  end
60
+ # TODO: Add XMI output.
61
+ # opts.on("-x", "--xmi", "Produce XMI instead of DOT",
62
+ # " (for UML tools)") do |x|
63
+ # self.xmi = x
64
+ # end
53
65
  opts.separator ""
54
66
  opts.separator "Models diagram options:"
55
67
  opts.on("-a", "--all", "Include all models",
@@ -65,6 +77,10 @@ class OptionsStruct < OpenStruct
65
77
  opts.on("-m", "--modules", "Include modules") do |m|
66
78
  self.modules = m
67
79
  end
80
+ opts.on("-t", "--transitive", "Include transitive associations",
81
+ "(through inheritance)") do |t|
82
+ self.transitive = t
83
+ end
68
84
  opts.separator ""
69
85
  opts.separator "Controllers diagram options:"
70
86
  opts.on("--hide-public", "Hide public methods") do |h|
@@ -123,8 +139,6 @@ class OptionsStruct < OpenStruct
123
139
  option_error "Invalid argument"
124
140
  rescue OptionParser::MissingArgument
125
141
  option_error "Missing argument"
126
- rescue
127
- option_error "Unknown error"
128
142
  end
129
143
  end # parse
130
144
 
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  SPEC = Gem::Specification.new do |s|
3
3
  s.name = "railroad"
4
- s.version = "0.3.4"
4
+ s.version = "0.4.0"
5
5
  s.author = "Javier Smaldone"
6
6
  s.email = "javier@smaldone.com.ar"
7
7
  s.homepage = "http://railroad.rubyforge.org"
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: railroad
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.4
7
- date: 2007-04-12 00:00:00 -03:00
6
+ version: 0.4.0
7
+ date: 2007-04-25 00:00:00 -03:00
8
8
  summary: A DOT diagram generator for Ruby on Rail applications
9
9
  require_paths:
10
10
  - lib