model_graph 0.1.1 → 0.1.2
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/bin/model_graph +19 -44
- data/lib/model_graph/version.rb +1 -1
- metadata +2 -2
data/bin/model_graph
CHANGED
@@ -40,8 +40,8 @@
|
|
40
40
|
# options is only a partial fix.
|
41
41
|
#
|
42
42
|
# === TODO:
|
43
|
-
# *
|
44
|
-
#
|
43
|
+
# * reverse some edges so nodes stay mostly balanced (close to same number of
|
44
|
+
# in and out edges)
|
45
45
|
# * handle indirect descendants of ActiveRecord::Base? (at least make it
|
46
46
|
# clearer how they're filtered out of the graph)
|
47
47
|
# * models that have no (outbound) associations are depicted in red, but
|
@@ -126,15 +126,9 @@ module ModelGraph
|
|
126
126
|
@nodes = Hash.new # holds simple strings
|
127
127
|
@edges = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = Hash.new } }
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
# A hm B :as => Y gives edge A->B and remembers polymorph Y->A
|
134
|
-
# C hm B :as => Y gives edge C->B and remembers polymorph Y->C
|
135
|
-
# B bt Y :polymorphic => true promises B->x for x in Y
|
136
|
-
|
137
|
-
@unresolved_edges = false
|
129
|
+
# A hm B :as => Y gives edge A->B and implies B bt A
|
130
|
+
# C hm B :as => Y gives edge C->B and implies B bt A
|
131
|
+
# B bt Y :polymorphic => true no new information
|
138
132
|
end
|
139
133
|
|
140
134
|
# Create an unattached node in this graph.
|
@@ -173,44 +167,20 @@ module ModelGraph
|
|
173
167
|
end] = v
|
174
168
|
end
|
175
169
|
end
|
176
|
-
if options.has_key?('midlabel')
|
177
|
-
add_polymorph(options['midlabel'], fromnode, options) # i.e., fill out edge later
|
178
|
-
end
|
179
170
|
end
|
180
171
|
|
181
172
|
# Iterates over all the DOT formatted edges with nodes having the most
|
182
173
|
# edges first and the edges without a constraint attribute before those
|
183
174
|
# that do.
|
184
175
|
def edges(options={}) # :yields: edgestring
|
185
|
-
self.resolve_edges if @unresolved_edges
|
186
176
|
@edges.sort { |a,b| b[1].length <=> a[1].length }.each do |(fromnode,nh)|
|
187
177
|
nh.sort_by { |(t,a)| (a.has_key?('constraint') ^ options[:constraints_first]) ? 1 : 0 }.each do |tonode,eh|
|
188
|
-
# if @polymorphs.has_key?(tonode) ... then loop over them
|
189
178
|
e = "#{fromnode} -> #{tonode} "
|
190
179
|
e << eh.inspect(options) unless eh.nil?
|
191
180
|
yield e
|
192
181
|
end
|
193
182
|
end
|
194
183
|
end
|
195
|
-
|
196
|
-
def add_polymorph(astype, fromnode, options={})
|
197
|
-
@polymorphs[astype] << fromnode
|
198
|
-
@unresolved_edges = true
|
199
|
-
end
|
200
|
-
|
201
|
-
def resolve_edges
|
202
|
-
puts "=> resolve_edges"
|
203
|
-
@polymorphs.each_pair do |fromnode, nodes|
|
204
|
-
puts " fromnode: #{fromnode.inspect} nodes: #{nodes.inspect}"
|
205
|
-
nodes.each do |tonode|
|
206
|
-
puts " tonode: #{tonode.inspect}"
|
207
|
-
add_edge(fromnode || "FUCK", tonode,
|
208
|
-
{ 'label' => :belongs_to.to_s,
|
209
|
-
'arrow' => ARROW_FOR[:belongs_to] })
|
210
|
-
end
|
211
|
-
end
|
212
|
-
@unresolved_edges = false
|
213
|
-
end
|
214
184
|
end
|
215
185
|
|
216
186
|
# classes that should not be graphed, but are subclasses of
|
@@ -321,11 +291,13 @@ module ModelGraph
|
|
321
291
|
end
|
322
292
|
|
323
293
|
next unless a.class_name == a.name.to_s.camelize.singularize
|
294
|
+
next if a.options[:polymorphic]
|
324
295
|
|
325
296
|
opts = { 'label' => a.macro.to_s, 'arrow' => ARROW_FOR[a.macro] }
|
326
297
|
opts.merge!('style' => 'dotted', 'constraint' => 'false') if a.through_reflection
|
327
|
-
opts.merge!('
|
328
|
-
|
298
|
+
opts.merge!('color' => 'blue', 'midlabel' => a.options[:as].to_s.camelize.singularize) if a.options[:as]
|
299
|
+
|
300
|
+
opts.merge!('color' => 'red') if a.options[:finder_sql]
|
329
301
|
|
330
302
|
fromnodename = klass.name
|
331
303
|
tonodename = a.name.to_s.camelize.singularize
|
@@ -338,15 +310,15 @@ module ModelGraph
|
|
338
310
|
graph.add_edge(tonodename, fromnodename, myopts)
|
339
311
|
standalone = false
|
340
312
|
end
|
341
|
-
if
|
342
|
-
graph.add_edge(fromnodename, tonodename, opts)
|
343
|
-
elsif klass.name == klass.class_name
|
313
|
+
if klass.name == klass.class_name
|
344
314
|
graph.add_edge(fromnodename, tonodename, opts)
|
315
|
+
if a.options[:as]
|
316
|
+
graph.add_edge(tonodename, fromnodename,
|
317
|
+
'arrow' => ARROW_FOR[:belongs_to], 'fontcolor' => 'blue')
|
318
|
+
end
|
345
319
|
standalone = false
|
346
320
|
elsif options.debug
|
347
321
|
output << " // !! skipping edge #{fromnodename} -> #{tonodename} #{opts.inspect}\n"
|
348
|
-
opts.merge!('midlabel' => klass.class_name)
|
349
|
-
graph.add_edge(fromnodename, tonodename, opts)
|
350
322
|
end
|
351
323
|
end
|
352
324
|
graph.add_node(klass.name, %{[color=red, fontcolor=red]}) if standalone
|
@@ -393,7 +365,7 @@ module ModelGraph
|
|
393
365
|
puts "sample: #{val}"
|
394
366
|
puts "__FILE__ = #{__FILE__}"
|
395
367
|
|
396
|
-
sample = File.join(File.dirname(__FILE__), '..', '
|
368
|
+
sample = File.join(File.dirname(__FILE__), '..', 'examples',
|
397
369
|
File.basename(val, ".rb") + '.rb')
|
398
370
|
if File.exists?(sample)
|
399
371
|
puts "getting #{sample} ..."
|
@@ -423,6 +395,10 @@ module ModelGraph
|
|
423
395
|
puts "name: #{val}"
|
424
396
|
options.name = val
|
425
397
|
end
|
398
|
+
opts.on("--shape=KIND", "override the shape of a node with a valid DOT shape") do |val|
|
399
|
+
puts "shape: #{val}"
|
400
|
+
options.shape = val
|
401
|
+
end
|
426
402
|
opts.on("--label", "-l", "show edge labels") { |val| options.label = true }
|
427
403
|
opts.on("--constraints-first", "--cf", "output constrained edges first (normally last)") do |val|
|
428
404
|
options.constraints_first = true
|
@@ -432,7 +408,6 @@ module ModelGraph
|
|
432
408
|
|
433
409
|
puts options.to_s
|
434
410
|
|
435
|
-
# unless (__FILE__ == $0 ? ARGV.include?('--test') : ENV.include?('TEST'))
|
436
411
|
unless options.test
|
437
412
|
for f in Dir.glob(File.join(RAILS_ROOT || '.', "app/models", "*.rb"))
|
438
413
|
puts "getting #{f}..."
|
data/lib/model_graph/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: model_graph
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.1.2
|
7
|
+
date: 2006-11-22 00:00:00 -05:00
|
8
8
|
summary: "When run from the trunk of a Rails project, produces # {DOT}[http://www.graphviz.org/doc/info/lang.html] output which can be # rendered into a graph by programs such as dot and neato and viewed with # Graphviz (an {Open Source}[http://www.graphviz.org/License.php] viewer)."
|
9
9
|
require_paths:
|
10
10
|
- lib
|