Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more robust model scanning

  • Loading branch information...
commit 78987c06094c9770eada0b4e60392015f3381fbb 1 parent 1d74614
@tiendung authored
View
12 bin/railroad
@@ -19,12 +19,12 @@ APP_HUMAN_NAME = "RailRoad"
APP_VERSION = [0,5,0]
COPYRIGHT = "Copyright (C) 2007-2008 Javier Smaldone"
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/options_struct'
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/diagram_graph'
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/app_diagram'
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/models_diagram'
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/controllers_diagram'
-require File.join File.dirname(__FILE__), '../lib/', 'railroad/aasm_diagram'
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/options_struct' )
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/diagram_graph' )
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/app_diagram' )
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/models_diagram' )
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/controllers_diagram' )
+require File.join( File.dirname(__FILE__), '../lib/', 'railroad/aasm_diagram' )
options = OptionsStruct.new
View
12 lib/railroad/aasm_diagram.rb
@@ -30,23 +30,13 @@ def generate
private
- def valid_model?( m )
- File.open( m, 'r') do |f|
- while (line = f.gets)
- return false if /ActionMailer|Observer/ =~ line
- end
- end
- return true
- end
-
# Load model classes
def load_classes
begin
disable_stdout
- files = Dir.glob("app/models/*.rb")
+ files = Dir.glob("app/models/**/*.rb")
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
files -= @options.exclude
- files = files.select{ |m| valid_model? m }
files.each {|m| require m }
enable_stdout
rescue LoadError
View
37 lib/railroad/models_diagram.rb
@@ -18,34 +18,37 @@ def initialize(options)
# Process model files
def generate
STDERR.print "Generating models diagram\n" if @options.verbose
- files = Dir.glob("app/models/*.rb")
+ base = "app/models/"
+ files = Dir.glob("app/models/**/*.rb")
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
files -= @options.exclude
- files = files.select{ |m| valid_model? m }
- files.each do |f|
- process_class extract_class_name(f).constantize
+ files.each do |file|
+ model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1')
+ # Hack to skip all xxx_related.rb files
+ next if /_related/i =~ model_name
+
+ klass = begin
+ model_name.classify.constantize
+ rescue LoadError
+ model_name.gsub!(/.*[\/\\]/, '')
+ retry
+ rescue NameError
+ next
+ end
+
+ process_class klass
end
end
private
- def valid_model?( m )
- File.open( m, 'r') do |f|
- while (line = f.gets)
- return false if /ActionMailer|Observer/ =~ line
- end
- end
- return true
- end
-
# Load model classes
def load_classes
begin
disable_stdout
- files = Dir.glob("app/models/*.rb")
+ files = Dir.glob("app/models/**/*.rb")
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
files -= @options.exclude
- files = files.select{ |m| valid_model? m }
files.each do |m|
require m
end
@@ -69,7 +72,7 @@ def process_class(current_class)
node_attribs = []
- if @options.brief || current_class.abstract_class?
+ if @options.brief || current_class.abstract_class? || current_class.superclass != ActiveRecord::Base
node_type = 'model-brief'
else
node_type = 'model'
@@ -150,7 +153,7 @@ def process_association(class_name, assoc)
else
assoc_name = assoc.name.to_s
end
-
+# STDERR.print "#{assoc_name}\n"
if assoc.macro.to_s == 'has_one'
assoc_type = 'one-one'
elsif assoc.macro.to_s == 'has_many' && (! assoc.options[:through])
View
9 tasks/diagrams.rake
@@ -1,15 +1,18 @@
namespace :doc do
namespace :diagram do
- ADDITIONAL_OPTS = "-j -v --hide-magic"
+ ADDITIONAL_OPTS = "-v -j --hide-magic"
RAILROAD = "./vendor/plugins/railroad/bin/railroad"
+ desc "Draw model diagram"
task :models do
- sh "#{RAILROAD} -i -l -m -M #{ADDITIONAL_OPTS} | dot -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/models.svg"
+ sh "#{RAILROAD} -i -m -M #{ADDITIONAL_OPTS} | dot -Tsvg | sed 's/font-size:12.00/font-size:11.00/g' > doc/models.svg"
end
+ desc "Draw controller diagram"
task :controllers do
- sh "#{RAILROAD} -i -l -C -v | neato -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/controllers.svg"
+ sh "#{RAILROAD} -i -C | neato -Tsvg | sed 's/font-size:12.00/font-size:11.00/g' > doc/controllers.svg"
end
end
+ desc "Draw model & controller diagrams"
task :diagrams => %w(diagram:models diagram:controllers)
end
Please sign in to comment.
Something went wrong with that request. Please try again.