ddollar-railroad 0.7.3 → 0.7.6
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.
- data/Manifest.txt +2 -1
- data/README.txt +6 -1
- data/lib/railroad.rb +1 -1
- data/lib/railroad/aasm_diagram.rb +41 -10
- data/lib/railroad/controllers_diagram.rb +17 -3
- data/lib/railroad/models_diagram.rb +17 -3
- data/lib/railroad/tasks/diagrams.rake +35 -0
- data/lib/railroad/tasks/diagrams.rb +1 -0
- metadata +6 -4
- data/tasks/diagrams.rake +0 -35
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -103,7 +103,10 @@ also use Omnigraffle (on Mac OS X).
|
|
103
103
|
|
104
104
|
= RailRoad as a rake task
|
105
105
|
|
106
|
-
See tasks/diagrams.rake
|
106
|
+
See lib/railroad/tasks/diagrams.rake
|
107
|
+
|
108
|
+
You can also add the following line in the Rakefile in your project:
|
109
|
+
require 'railroad/tasks/diagrams' if RAILS_ENV == 'development'
|
107
110
|
|
108
111
|
= Requirements
|
109
112
|
|
@@ -136,3 +139,5 @@ Tien Dung http://github.com/tiendung
|
|
136
139
|
Factory Design Labs http://github.com/factorylabs
|
137
140
|
Mike Mondragon http://github.com/monde
|
138
141
|
Tero Tilus http://github.com/terotil
|
142
|
+
Bruno Michel http://github.com/nono
|
143
|
+
|
data/lib/railroad.rb
CHANGED
@@ -28,7 +28,7 @@ class AasmDiagram < AppDiagram
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
private
|
32
32
|
|
33
33
|
# Load model classes
|
34
34
|
def load_classes
|
@@ -37,7 +37,7 @@ class AasmDiagram < AppDiagram
|
|
37
37
|
files = Dir.glob("app/models/**/*.rb")
|
38
38
|
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
|
39
39
|
files -= @options.exclude
|
40
|
-
files.each {|
|
40
|
+
files.each {|file| get_model_class(file) }
|
41
41
|
enable_stdout
|
42
42
|
rescue LoadError
|
43
43
|
enable_stdout
|
@@ -46,25 +46,56 @@ class AasmDiagram < AppDiagram
|
|
46
46
|
end
|
47
47
|
end # load_classes
|
48
48
|
|
49
|
+
# This method is taken from the annotate models gem
|
50
|
+
# http://github.com/ctran/annotate_models/tree/master
|
51
|
+
#
|
52
|
+
# Retrieve the classes belonging to the model names we're asked to process
|
53
|
+
# Check for namespaced models in subdirectories as well as models
|
54
|
+
# in subdirectories without namespacing.
|
55
|
+
def get_model_class(file)
|
56
|
+
model = file.sub(/^.*app\/models\//, '').sub(/\.rb$/, '').camelize
|
57
|
+
parts = model.split('::')
|
58
|
+
begin
|
59
|
+
parts.inject(Object) {|klass, part| klass.const_get(part) }
|
60
|
+
rescue LoadError
|
61
|
+
Object.const_get(parts.last)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
49
65
|
# Process a model class
|
50
66
|
def process_class(current_class)
|
51
67
|
|
52
68
|
STDERR.print "\tProcessing #{current_class}\n" if @options.verbose
|
53
|
-
|
69
|
+
|
70
|
+
states = nil
|
71
|
+
if current_class.respond_to? 'states'
|
72
|
+
states = current_class.states
|
73
|
+
initial = current_class.initial_state
|
74
|
+
events = current_class.read_inheritable_attribute(:transition_table)
|
75
|
+
elsif current_class.respond_to? 'aasm_states'
|
76
|
+
states = current_class.aasm_states.map { |s| s.name }
|
77
|
+
initial = current_class.aasm_initial_state
|
78
|
+
events = current_class.aasm_events
|
79
|
+
end
|
80
|
+
|
54
81
|
# Only interested in acts_as_state_machine models.
|
55
|
-
return
|
56
|
-
|
82
|
+
return if states.nil? || states.empty?
|
83
|
+
|
57
84
|
node_attribs = []
|
58
85
|
node_type = 'aasm'
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
node_shape = (current_class.initial_state === state_name) ? ", peripheries = 2" : ""
|
86
|
+
|
87
|
+
states.each do |state_name|
|
88
|
+
node_shape = (initial === state_name) ? ", peripheries = 2" : ""
|
63
89
|
node_attribs << "#{current_class.name.downcase}_#{state_name} [label=#{state_name} #{node_shape}];"
|
64
90
|
end
|
65
91
|
@graph.add_node [node_type, current_class.name, node_attribs]
|
66
92
|
|
67
|
-
|
93
|
+
events.each do |event_name, event|
|
94
|
+
if !event.respond_to?('each')
|
95
|
+
def event.each(&blk)
|
96
|
+
@transitions.each { |t| blk.call(t) }
|
97
|
+
end
|
98
|
+
end
|
68
99
|
event.each do |transition|
|
69
100
|
@graph.add_edge [
|
70
101
|
'event',
|
@@ -30,10 +30,8 @@ class ControllersDiagram < AppDiagram
|
|
30
30
|
def load_classes
|
31
31
|
begin
|
32
32
|
disable_stdout
|
33
|
-
# ApplicationController must be loaded first
|
34
|
-
require "app/controllers/application_controller.rb"
|
35
33
|
files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
|
36
|
-
files.each {|
|
34
|
+
files.each {|file| get_controller_class(file) }
|
37
35
|
enable_stdout
|
38
36
|
rescue LoadError
|
39
37
|
enable_stdout
|
@@ -42,6 +40,22 @@ class ControllersDiagram < AppDiagram
|
|
42
40
|
end
|
43
41
|
end # load_classes
|
44
42
|
|
43
|
+
# This method is taken from the annotate models gem
|
44
|
+
# http://github.com/ctran/annotate_models/tree/master
|
45
|
+
#
|
46
|
+
# Retrieve the classes belonging to the controller names we're asked to process
|
47
|
+
# Check for namespaced controllers in subdirectories as well as controllers
|
48
|
+
# in subdirectories without namespacing.
|
49
|
+
def get_controller_class(file)
|
50
|
+
model = file.sub(/^.*app\/controllers\//, '').sub(/\.rb$/, '').camelize
|
51
|
+
parts = model.split('::')
|
52
|
+
begin
|
53
|
+
parts.inject(Object) {|klass, part| klass.const_get(part) }
|
54
|
+
rescue LoadError
|
55
|
+
Object.const_get(parts.last)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
# Proccess a controller class
|
46
60
|
def process_class(current_class)
|
47
61
|
|
@@ -63,9 +63,7 @@ class ModelsDiagram < AppDiagram
|
|
63
63
|
files = Dir.glob("app/models/**/*.rb")
|
64
64
|
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
|
65
65
|
files -= @options.exclude
|
66
|
-
files.each
|
67
|
-
require m
|
68
|
-
end
|
66
|
+
files.each {|file| get_model_class(file) }
|
69
67
|
enable_stdout
|
70
68
|
rescue LoadError
|
71
69
|
enable_stdout
|
@@ -74,6 +72,22 @@ class ModelsDiagram < AppDiagram
|
|
74
72
|
end
|
75
73
|
end # load_classes
|
76
74
|
|
75
|
+
# This method is taken from the annotate models gem
|
76
|
+
# http://github.com/ctran/annotate_models/tree/master
|
77
|
+
#
|
78
|
+
# Retrieve the classes belonging to the model names we're asked to process
|
79
|
+
# Check for namespaced models in subdirectories as well as models
|
80
|
+
# in subdirectories without namespacing.
|
81
|
+
def get_model_class(file)
|
82
|
+
model = file.sub(/^.*app\/models\//, '').sub(/\.rb$/, '').camelize
|
83
|
+
parts = model.split('::')
|
84
|
+
begin
|
85
|
+
parts.inject(Object) {|klass, part| klass.const_get(part) }
|
86
|
+
rescue LoadError
|
87
|
+
Object.const_get(parts.last)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
77
91
|
# Process a model class
|
78
92
|
def process_class(current_class)
|
79
93
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
namespace :doc do
|
2
|
+
namespace :diagrams do
|
3
|
+
desc "Draw model diagrams"
|
4
|
+
task :models do
|
5
|
+
doc_diagrams_generate('models', '-a -m -M', 'neato')
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Draw controller diagrams"
|
9
|
+
task :controllers do
|
10
|
+
doc_diagrams_generate('controllers', '-C', 'neato')
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Draw states diagrams"
|
14
|
+
task :states do
|
15
|
+
doc_diagrams_generate('states', '-A', 'dot')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Draw controllers, models & states diagrams"
|
20
|
+
task :diagrams => %w(diagrams:models diagrams:controllers diagrams:states)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def doc_diagrams_generate(type, options, dot_cmd)
|
25
|
+
railroad = "railroad" # or "./vendor/plugins/railroad/bin/railroad"
|
26
|
+
options = "-v -j -l -i #{options}"
|
27
|
+
output_dir = "doc/diagrams"
|
28
|
+
|
29
|
+
FileUtils.mkdir(output_dir) unless File.exist?(output_dir)
|
30
|
+
|
31
|
+
sh "#{railroad} -o #{output_dir}/#{type}.dot #{options}"
|
32
|
+
sh "#{dot_cmd} -Tpng #{output_dir}/#{type}.dot -o #{output_dir}/#{type}.png"
|
33
|
+
sh "#{dot_cmd} -Tsvg #{output_dir}/#{type}.dot | sed 's/font-size:14.00/font-size:11px/g' > #{output_dir}/#{type}.svg"
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
load 'railroad/tasks/diagrams.rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddollar-railroad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Smaldone
|
@@ -11,11 +11,12 @@ authors:
|
|
11
11
|
- Mike Mondragon
|
12
12
|
- Tero Tilus
|
13
13
|
- David Dollar
|
14
|
+
- Bruno Michel
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2009-
|
19
|
+
date: 2009-03-14 00:00:00 -07:00
|
19
20
|
default_executable: railroad
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +29,7 @@ dependencies:
|
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: 1.7.0
|
30
31
|
version:
|
31
|
-
description:
|
32
|
+
description: RailRoad is a class diagrams generator for Ruby on Rails applications.
|
32
33
|
email: javier@smaldone.com.ar
|
33
34
|
executables:
|
34
35
|
- railroad
|
@@ -54,7 +55,8 @@ files:
|
|
54
55
|
- lib/railroad/diagram_graph.rb
|
55
56
|
- lib/railroad/models_diagram.rb
|
56
57
|
- lib/railroad/options_struct.rb
|
57
|
-
- tasks/diagrams.
|
58
|
+
- lib/railroad/tasks/diagrams.rb
|
59
|
+
- lib/railroad/tasks/diagrams.rake
|
58
60
|
has_rdoc: true
|
59
61
|
homepage: http://railroad.rubyforge.org
|
60
62
|
post_install_message:
|
data/tasks/diagrams.rake
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
namespace :doc do
|
2
|
-
namespace :diagram do
|
3
|
-
desc "Draw model diagram"
|
4
|
-
task :models do
|
5
|
-
classmap = {
|
6
|
-
# 'app/models/model_with_nasty_name' => 'ModelWithNastyNAME',
|
7
|
-
}.to_a.join(',')
|
8
|
-
exclude =
|
9
|
-
[
|
10
|
-
# 'app/models/model_to_exclude.rb',
|
11
|
-
].join(',')
|
12
|
-
opts =
|
13
|
-
[
|
14
|
-
'--models',
|
15
|
-
'--inheritance',
|
16
|
-
'--label',
|
17
|
-
'--all',
|
18
|
-
'--modules',
|
19
|
-
# '--libraries',
|
20
|
-
# '--verbose',
|
21
|
-
].join(' ')
|
22
|
-
FileUtils.mkdir('doc/app') unless File.exist?('doc/app')
|
23
|
-
sh "railroad #{opts} --class-map=#{classmap} --exclude=#{exclude} | dot -Tsvg | sed 's/font-size:14.00/font-size:11px/g' > doc/app/models.svg"
|
24
|
-
end
|
25
|
-
|
26
|
-
desc "Draw controller diagram"
|
27
|
-
task :controllers do
|
28
|
-
FileUtils.mkdir('doc/app') unless File.exist?('doc/app')
|
29
|
-
sh "railroad -i -C | neato -Tsvg | sed 's/font-size:14.00/font-size:11px/g' > doc/app/controllers.svg"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Draw model & controller diagrams"
|
34
|
-
task :diagrams => %w(diagram:models diagram:controllers)
|
35
|
-
end
|