railroady 1.1.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/AUTHORS.rdoc +1 -1
- data/Gemfile +2 -1
- data/Gemfile.lock +19 -18
- data/Guardfile +49 -0
- data/README.md +221 -0
- data/Rakefile +5 -5
- data/bin/railroady +9 -8
- data/lib/railroady/aasm_diagram.rb +32 -67
- data/lib/railroady/app_diagram.rb +41 -38
- data/lib/railroady/controllers_diagram.rb +50 -45
- data/lib/railroady/diagram_graph.rb +68 -81
- data/lib/railroady/models_diagram.rb +78 -63
- data/lib/railroady/options_struct.rb +115 -111
- data/lib/railroady/railtie.rb +7 -5
- data/lib/railroady/version.rb +3 -1
- data/lib/railroady.rb +10 -2
- data/railroady.gemspec +16 -17
- data/tasks/railroady.rake +57 -16
- data/test/file_fixture/app/controllers/application_controller.rb +1 -1
- data/test/file_fixture/app/models/concerns/author_settings.rb +12 -0
- data/test/file_fixture/app/models/concerns/taggable.rb +0 -0
- data/test/file_fixture/lib/app/controllers/dummy/dummy_controller.rb +0 -0
- data/test/file_fixture/lib/app/models/dummy1.rb +0 -0
- data/test/lib/railroady/aasm_diagram_spec.rb +19 -14
- data/test/lib/railroady/app_diagram_spec.rb +1 -2
- data/test/lib/railroady/controllers_diagram_spec.rb +20 -13
- data/test/lib/railroady/core_ext_spec.rb +2 -2
- data/test/lib/railroady/diagram_graph_spec.rb +17 -13
- data/test/lib/railroady/models_diagram_spec.rb +126 -13
- data/test/spec_helper.rb +2 -2
- metadata +23 -29
- data/CHANGELOG.rdoc +0 -144
- data/README.rdoc +0 -187
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e60172ea20b64daead4e5a040e50c92e411a0ea0824d4bb6836978d16ce7cf82
|
4
|
+
data.tar.gz: d1fb29719573215458dfb3cacf01d0d96a5b98a479accd0688ddd4cab231f5ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 458f52b7f8f07b1abae06ee141a4a098f67e8882b1087383d4cfee6d642d2f766cb2937037ee39e87a1c68aadce9321c9c208470423fa8982d17b8bbd0a15f48
|
7
|
+
data.tar.gz: 9d8e33334f7727d5f7049446416328f91f2221d3d8ee261300e44c7507174b4610bab7c447d3511c773bc962dcc73661711493a069a2132bbbd67e06783417f0
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/AUTHORS.rdoc
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
railroady (1.
|
4
|
+
railroady (1.6.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
i18n (
|
17
|
-
|
18
|
-
minitest
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
tzinfo (0.3.37)
|
9
|
+
activesupport (6.1.4)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
zeitwerk (~> 2.3)
|
15
|
+
concurrent-ruby (1.1.9)
|
16
|
+
i18n (1.8.10)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
minitest (5.14.4)
|
19
|
+
rake (13.0.6)
|
20
|
+
tzinfo (2.0.4)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
zeitwerk (2.4.2)
|
24
23
|
|
25
24
|
PLATFORMS
|
26
|
-
|
25
|
+
x86_64-darwin-20
|
27
26
|
|
28
27
|
DEPENDENCIES
|
29
28
|
activesupport
|
30
29
|
bundler
|
31
30
|
minitest
|
32
|
-
minitest-spec-context
|
33
31
|
railroady!
|
34
32
|
rake
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.2.22
|
data/Guardfile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
clearing :on
|
9
|
+
|
10
|
+
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
+
## If you want Guard to automatically start up again, run guard in a
|
12
|
+
## shell loop, e.g.:
|
13
|
+
##
|
14
|
+
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
+
##
|
16
|
+
## Note: if you are using the `directories` clause above and you are not
|
17
|
+
## watching the project directory ('.'), the you will want to move the Guardfile
|
18
|
+
## to a watched dir and symlink it back, e.g.
|
19
|
+
#
|
20
|
+
# $ mkdir config
|
21
|
+
# $ mv Guardfile config/
|
22
|
+
# $ ln -s config/Guardfile .
|
23
|
+
#
|
24
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
+
|
26
|
+
guard :minitest do
|
27
|
+
# with Minitest::Unit
|
28
|
+
# watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
29
|
+
# watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
30
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
31
|
+
|
32
|
+
# with Minitest::Spec
|
33
|
+
# watch(%r{^spec/(.*)_spec\.rb$})
|
34
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
35
|
+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
36
|
+
|
37
|
+
watch(%r{^test/(.*)_spec\.rb$})
|
38
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_spec.rb" }
|
39
|
+
watch(%r{^test/spec_helper\.rb$}) { 'test' }
|
40
|
+
|
41
|
+
# Rails 4
|
42
|
+
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
43
|
+
# watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
|
44
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
|
45
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
46
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
47
|
+
# watch(%r{^test/.+_test\.rb$})
|
48
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
49
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
# RailRoady
|
2
|
+
|
3
|
+
[](https://travis-ci.org/preston/railroady)
|
4
|
+
|
5
|
+
RailRoady generates Rails 3/4/5 model (ActiveRecord, Mongoid, Datamapper) and controller UML diagrams as cross-platform .svg files, as well as in the DOT language.
|
6
|
+
|
7
|
+
Code is based on the original "railroad" gem, patched and maintained over the years. Lineage can be traced via GitHub.
|
8
|
+
|
9
|
+
I (Preston Lee) am not trying to hijack Peter Hoeg or Javier's project, but rather create a dedicated, lean gem that can be used without major issue on Rails projects. Rails v2 is not supported.
|
10
|
+
|
11
|
+
# System Requirements
|
12
|
+
|
13
|
+
You MUST have the the following utilities available at the command line.
|
14
|
+
* `dot` and `neato`.
|
15
|
+
|
16
|
+
* `sed`, which should already be available on all sane UNIX systems.
|
17
|
+
|
18
|
+
## Mac users
|
19
|
+
|
20
|
+
Brew users can install via:
|
21
|
+
|
22
|
+
brew install graphviz
|
23
|
+
|
24
|
+
MacPorts users can install in via
|
25
|
+
|
26
|
+
sudo port install graphviz
|
27
|
+
|
28
|
+
|
29
|
+
## Ubuntu users
|
30
|
+
|
31
|
+
Ubuntu users can install in via
|
32
|
+
|
33
|
+
sudo apt-get install graphviz
|
34
|
+
|
35
|
+
# Usage
|
36
|
+
|
37
|
+
The easiest (and recommend) usage is to include railroady as a development dependency with your Rails 3 Gemfile, like so...
|
38
|
+
|
39
|
+
group :development, :test do
|
40
|
+
gem 'railroady'
|
41
|
+
end
|
42
|
+
|
43
|
+
...and then run the master rake task...
|
44
|
+
|
45
|
+
rake diagram:all
|
46
|
+
|
47
|
+
This should generate four doc/\*.svg files that can be opened in (most) web browsers as well as dedicated document viewers supporting the Scalable Vector Graphics format.
|
48
|
+
|
49
|
+
## Support for Engines
|
50
|
+
|
51
|
+
Generate diagram for models and controllers including those in the engines.
|
52
|
+
|
53
|
+
rake diagram:all_with_engines
|
54
|
+
|
55
|
+
## Alternate Usage
|
56
|
+
|
57
|
+
Alternatively, you may run the 'railroady' command-line program at the Rails application's root directory. You can redirect its output to a .dot file or pipe it to the dot or neato utilities to produce a graphic. Model diagrams are intended to be processed using dot and controller diagrams are best processed using neato.
|
58
|
+
|
59
|
+
railroady [options] command
|
60
|
+
|
61
|
+
## Options
|
62
|
+
|
63
|
+
Common options:
|
64
|
+
-b, --brief Generate compact diagram
|
65
|
+
(no attributes nor methods)
|
66
|
+
-s, --specify file1[,fileN] Specify only given files
|
67
|
+
-e, --exclude file1[,fileN] Exclude given files
|
68
|
+
-i, --inheritance Include inheritance relations
|
69
|
+
-l, --label Add a label with diagram information
|
70
|
+
(type, date, migration, version)
|
71
|
+
-o, --output FILE Write diagram to file FILE
|
72
|
+
-r, --root PATH Set PATH as the application root
|
73
|
+
-v, --verbose Enable verbose output
|
74
|
+
(produce messages to STDOUT)
|
75
|
+
-x, --xmi Produce XMI instead of DOT
|
76
|
+
(for UML tools)
|
77
|
+
--alphabetize Sort methods alphabetically
|
78
|
+
|
79
|
+
Models diagram options:
|
80
|
+
-a, --all Include all models
|
81
|
+
(not only ActiveRecord::Base derived)
|
82
|
+
--show-belongs_to Show belongs_to associations
|
83
|
+
--hide-through Hide through associations
|
84
|
+
--all-columns Show all columns (not just content columns)
|
85
|
+
--hide-magic Hide magic field names
|
86
|
+
--hide-types Hide attributes type
|
87
|
+
-j, --join Concentrate edges
|
88
|
+
-m, --modules Include modules
|
89
|
+
-p, --plugins-models Include plugins models
|
90
|
+
-z, --engine-models Include engine models
|
91
|
+
--include-concerns Include models in concerns subdirectory
|
92
|
+
-t, --transitive Include transitive associations
|
93
|
+
(through inheritance)
|
94
|
+
|
95
|
+
Controllers diagram options:
|
96
|
+
--hide-public Hide public methods
|
97
|
+
--hide-protected Hide protected methods
|
98
|
+
--hide-private Hide private methods
|
99
|
+
--engine-controllers Include engine controllers
|
100
|
+
|
101
|
+
Other options:
|
102
|
+
-h, --help Show this message
|
103
|
+
--version Show version and copyright
|
104
|
+
|
105
|
+
-c, --config FILE File to load environment (defaults to config/environment)
|
106
|
+
|
107
|
+
## Commands
|
108
|
+
|
109
|
+
You must supply one of these:
|
110
|
+
|
111
|
+
-M, --models Generate models diagram
|
112
|
+
-C, --controllers Generate controllers diagram
|
113
|
+
-A, --aasm Generate "acts as state machine" diagram
|
114
|
+
|
115
|
+
## Examples
|
116
|
+
|
117
|
+
railroady -o models.dot -M
|
118
|
+
Produces a models diagram to the file 'models.dot'
|
119
|
+
railroady -a -i -o full_models.dot -M
|
120
|
+
Models diagram with all classes showing inheritance relations
|
121
|
+
railroady -M | dot -Tsvg > models.svg
|
122
|
+
Model diagram in SVG format
|
123
|
+
railroady -C | neato -Tpng > controllers.png
|
124
|
+
Controller diagram in PNG format
|
125
|
+
railroady -h
|
126
|
+
Shows usage help
|
127
|
+
|
128
|
+
|
129
|
+
# Processing DOT files
|
130
|
+
|
131
|
+
To produce a PNG image from model diagram generated by RailRoady you can
|
132
|
+
issue the following command:
|
133
|
+
|
134
|
+
dot -Tpng models.dot > models.png
|
135
|
+
|
136
|
+
If you want to do the same with a controller diagram, use neato instead of
|
137
|
+
dot:
|
138
|
+
|
139
|
+
neato -Tpng controllers.dot > controllers.png
|
140
|
+
|
141
|
+
If you want to produce SVG (vectorial, scalable, editable) files, you can do
|
142
|
+
the following:
|
143
|
+
|
144
|
+
dot -Tsvg models.dot > models.svg
|
145
|
+
neato -Tsvg controllers.dot > controllers.svg
|
146
|
+
|
147
|
+
Important: There is a bug in Graphviz tools when generating SVG files that
|
148
|
+
cause a text overflow. You can solve this problem editing (with a text
|
149
|
+
editor, not a graphical SVG editor) the file and replacing around line 12
|
150
|
+
"font-size:14.00;" by "font-size:11.00;", or by issuing the following command
|
151
|
+
(see "man sed"):
|
152
|
+
|
153
|
+
sed -i 's/font-size:14.00/font-size:11.00/g' file.svg
|
154
|
+
|
155
|
+
Note: For viewing and editing SVG there is an excellent opensource tool
|
156
|
+
called Inkscape (similar to Adobe Illustrator. For DOT processing you can
|
157
|
+
also use Omnigraffle (on Mac OS X).
|
158
|
+
|
159
|
+
= Rake Tasks
|
160
|
+
|
161
|
+
As of Preston Lee's Rails 3/4/5 modifications, including RailRoady as a project development dependency will automatically add a set of rake tasks to your project. Sweet! (Run `rake -T` to check them out.)
|
162
|
+
|
163
|
+
|
164
|
+
# Requirements
|
165
|
+
|
166
|
+
RailRoady has been tested with the following Ruby and Rails versions
|
167
|
+
|
168
|
+
## Ruby
|
169
|
+
* 1.9.2+
|
170
|
+
* 2.0.0+
|
171
|
+
|
172
|
+
## Rails
|
173
|
+
* 3.0.3+
|
174
|
+
* 4.0.0+
|
175
|
+
* 5.0.0+
|
176
|
+
|
177
|
+
There are no additional requirements (nevertheless, all your Rails application
|
178
|
+
requirements must be installed).
|
179
|
+
|
180
|
+
In order to view/export the DOT diagrams, you'll need the processing tools
|
181
|
+
from Graphviz.
|
182
|
+
|
183
|
+
= Website and Project Home
|
184
|
+
|
185
|
+
http://railroady.prestonlee.com
|
186
|
+
|
187
|
+
# License
|
188
|
+
|
189
|
+
RailRoady is distributed under the terms of the GNU General Public License
|
190
|
+
as published by the Free Software Foundation; either version 2 of the
|
191
|
+
License, or (at your option) any later version.
|
192
|
+
|
193
|
+
See LICENSE for details.
|
194
|
+
|
195
|
+
## Copyright
|
196
|
+
|
197
|
+
Copyright (c) 2007-2008 Javier Smaldone
|
198
|
+
Copyright (c) 2009 Peter Hoeg
|
199
|
+
Copyright (c) 2010-2016 Preston Lee
|
200
|
+
|
201
|
+
See LICENSE for details.
|
202
|
+
|
203
|
+
## Authors
|
204
|
+
|
205
|
+
Authors/Contributors (in approximate order of appearance):
|
206
|
+
|
207
|
+
* Javier Smaldone (javier |at| smaldone |dot| com |dot| ar)
|
208
|
+
* Elliot Smith
|
209
|
+
* Juan Ignacio Pumarino
|
210
|
+
* Hajime Baba
|
211
|
+
* Ana Nelson
|
212
|
+
* Peter Hoeg
|
213
|
+
* John McCaffrey
|
214
|
+
* David Jones
|
215
|
+
* Mike Dalessio
|
216
|
+
* [Preston Lee](https://www.prestonlee.com) and [Lee Does](https://www.leedoes.com), the vendor providing maintenance.
|
217
|
+
* Tim Harvey
|
218
|
+
* Atli Christiansen
|
219
|
+
* John Bintz (http://www.coswellproductions.com/)
|
220
|
+
|
221
|
+
And of course, many thanks to the many patch submitters and testers that make this possible!
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
4
|
require 'rake/testtask'
|
5
|
-
|
5
|
+
|
6
6
|
Rake::TestTask.new do |t|
|
7
7
|
t.libs << 'lib/railroady'
|
8
8
|
t.test_files = FileList['test/lib/railroady/*_spec.rb']
|
9
9
|
t.verbose = true
|
10
10
|
end
|
11
|
-
|
12
|
-
task :
|
11
|
+
|
12
|
+
task default: :test
|
data/bin/railroady
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
# RailRoady - RoR diagrams generator
|
4
5
|
# http://github.com/preston/railroady
|
@@ -13,19 +14,20 @@
|
|
13
14
|
# the Free Software Foundation; either version 2 of the License, or
|
14
15
|
# (at your option) any later version.
|
15
16
|
#
|
16
|
-
#
|
17
|
+
# Modifications 2010-2015 by Preston Lee.
|
17
18
|
#
|
18
19
|
|
19
20
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
21
|
require 'railroady'
|
21
22
|
|
22
|
-
APP_NAME =
|
23
|
-
APP_HUMAN_NAME =
|
23
|
+
APP_NAME = 'railroady'
|
24
|
+
APP_HUMAN_NAME = 'RailRoady'
|
24
25
|
# APP_VERSION = [RailRoady::VERSION::MAJOR, RailRoady::VERSION::MINOR, RailRoady::VERSION::PATCH]
|
25
26
|
APP_VERSION = RailRoady::VERSION
|
26
|
-
COPYRIGHT =
|
27
|
+
COPYRIGHT = 'Copyright (C) 2007-2008 Javier Smaldone, 2009 Peter Hoeg, 2010-2015 Preston Lee'
|
27
28
|
|
28
|
-
options = OptionsStruct.new(
|
29
|
+
options = OptionsStruct.new(app_name: APP_NAME, app_human_name: APP_HUMAN_NAME, app_version: APP_VERSION,
|
30
|
+
copyright: COPYRIGHT)
|
29
31
|
|
30
32
|
options.parse ARGV
|
31
33
|
|
@@ -44,8 +46,8 @@ when 'controllers'
|
|
44
46
|
when 'aasm'
|
45
47
|
diagram = AasmDiagram.new(options)
|
46
48
|
else
|
47
|
-
|
48
|
-
"Error: You must supply a command\n"
|
49
|
+
$stderr.print "#{APP_HUMAN_NAME} v#{APP_VERSION}\n" \
|
50
|
+
"Error: You must supply a command\n" \
|
49
51
|
" (try #{APP_NAME} -h)\n\n"
|
50
52
|
exit 1
|
51
53
|
end
|
@@ -56,4 +58,3 @@ diagram.generate
|
|
56
58
|
Dir.chdir(old_dir)
|
57
59
|
|
58
60
|
diagram.print
|
59
|
-
|
@@ -1,18 +1,11 @@
|
|
1
|
-
#
|
2
|
-
# http://railroad.rubyforge.org
|
3
|
-
#
|
4
|
-
# Copyright 2007-2008 - Javier Smaldone (http://www.smaldone.com.ar)
|
5
|
-
# See COPYING for more details
|
6
|
-
|
7
|
-
# AASM code provided by Ana Nelson (http://ananelson.com/)
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
3
|
require 'railroady/app_diagram'
|
10
4
|
|
11
5
|
# Diagram for Acts As State Machine
|
12
6
|
class AasmDiagram < AppDiagram
|
13
|
-
|
14
7
|
def initialize(options = OptionsStruct.new)
|
15
|
-
#options.exclude.map! {|e| e = "app/models/" + e}
|
8
|
+
# options.exclude.map! {|e| e = "app/models/" + e}
|
16
9
|
super options
|
17
10
|
@graph.diagram_type = 'Models'
|
18
11
|
# Processed habtm associations
|
@@ -21,89 +14,61 @@ class AasmDiagram < AppDiagram
|
|
21
14
|
|
22
15
|
# Process model files
|
23
16
|
def generate
|
24
|
-
|
17
|
+
$stderr.print "Generating AASM diagram\n" if @options.verbose
|
25
18
|
get_files.each do |f|
|
26
19
|
process_class extract_class_name(f).constantize
|
27
20
|
end
|
28
21
|
end
|
29
22
|
|
30
|
-
def get_files(prefix ='')
|
31
|
-
files = !@options.specify.empty? ? Dir.glob(@options.specify) : Dir.glob(prefix
|
32
|
-
files += Dir.glob(
|
33
|
-
files
|
34
|
-
|
23
|
+
def get_files(prefix = '')
|
24
|
+
files = !@options.specify.empty? ? Dir.glob(@options.specify) : Dir.glob("#{prefix}app/models/**/*.rb")
|
25
|
+
files += Dir.glob('vendor/plugins/**/app/models/*.rb') if @options.plugins_models
|
26
|
+
files - Dir.glob("#{prefix}app/models/concerns/**/*.rb") unless @options.include_concerns
|
27
|
+
Dir.glob(@options.exclude)
|
35
28
|
end
|
36
29
|
|
37
30
|
private
|
38
31
|
|
39
32
|
# Load model classes
|
40
33
|
def load_classes
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
end # load_classes
|
34
|
+
disable_stdout
|
35
|
+
get_files.each { |m| require m }
|
36
|
+
enable_stdout
|
37
|
+
rescue LoadError
|
38
|
+
enable_stdout
|
39
|
+
print_error 'model classes'
|
40
|
+
raise
|
41
|
+
end
|
51
42
|
|
52
43
|
# Process a model class
|
53
44
|
def process_class(current_class)
|
45
|
+
$stderr.print "\tProcessing #{current_class}\n" if @options.verbose
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
# Only interested in acts_as_state_machine models.
|
58
|
-
process_acts_as_state_machine_class(current_class) if current_class.respond_to?(:states)
|
59
|
-
process_aasm_class(current_class) if current_class.respond_to?(:aasm_states)
|
60
|
-
end # process_class
|
61
|
-
|
62
|
-
def process_acts_as_state_machine_class(current_class)
|
63
|
-
node_attribs = []
|
64
|
-
node_type = 'aasm'
|
65
|
-
|
66
|
-
STDERR.print "\t\tprocessing as acts_as_state_machine\n" if @options.verbose
|
67
|
-
current_class.states.each do |state_name|
|
68
|
-
state = current_class.read_inheritable_attribute(:states)[state_name]
|
69
|
-
node_shape = (current_class.initial_state === state_name) ? ", peripheries = 2" : ""
|
70
|
-
node_attribs << "#{current_class.name.downcase}_#{state_name} [label=#{state_name} #{node_shape}];"
|
71
|
-
end
|
72
|
-
@graph.add_node [node_type, current_class.name, node_attribs]
|
73
|
-
|
74
|
-
current_class.read_inheritable_attribute(:transition_table).each do |event_name, event|
|
75
|
-
event.each do |transition|
|
76
|
-
@graph.add_edge [
|
77
|
-
'event',
|
78
|
-
current_class.name.downcase + "_" + transition.from.to_s,
|
79
|
-
current_class.name.downcase + "_" + transition.to.to_s,
|
80
|
-
event_name.to_s
|
81
|
-
]
|
82
|
-
end
|
83
|
-
end
|
47
|
+
# Only interested in aasm models.
|
48
|
+
process_aasm_class(current_class) if current_class.respond_to?(:aasm_states) || current_class.respond_to?(:aasm)
|
84
49
|
end
|
85
50
|
|
86
51
|
def process_aasm_class(current_class)
|
87
52
|
node_attribs = []
|
88
53
|
node_type = 'aasm'
|
54
|
+
diagram_friendly_class_name = current_class.name.downcase.gsub(/[^a-z0-9\-_]+/i, '_')
|
89
55
|
|
90
|
-
|
91
|
-
current_class.
|
92
|
-
node_shape =
|
93
|
-
node_attribs << "#{
|
56
|
+
$stderr.print "\t\tprocessing as aasm\n" if @options.verbose
|
57
|
+
current_class.aasm.states.each do |state|
|
58
|
+
node_shape = current_class.aasm.initial_state == state.name ? ', peripheries = 2' : ''
|
59
|
+
node_attribs << "#{diagram_friendly_class_name}_#{state.name} [label=#{state.name} #{node_shape}];"
|
94
60
|
end
|
95
61
|
@graph.add_node [node_type, current_class.name, node_attribs]
|
96
62
|
|
97
|
-
current_class.
|
98
|
-
event.
|
63
|
+
current_class.aasm.events.each do |event|
|
64
|
+
event.transitions.each do |transition|
|
99
65
|
@graph.add_edge [
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
66
|
+
'event',
|
67
|
+
"#{diagram_friendly_class_name}_#{transition.from}",
|
68
|
+
"#{diagram_friendly_class_name}_#{transition.to}",
|
69
|
+
event.name.to_s
|
70
|
+
]
|
105
71
|
end
|
106
72
|
end
|
107
73
|
end
|
108
|
-
|
109
|
-
end # class AasmDiagram
|
74
|
+
end
|