Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Hi! We cleaned up your code for you! #1

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+93 −93
Split
View
@@ -1,8 +1,8 @@
Version 0.5.0 (may 10 2008)
- Changed model relationships representation (feature request #10898)
-- Added support for plugins models (-p) (feature request #12742 by
+- Added support for plugins models (-p) (feature request #12742 by
Chris Richards). Thanks to Elliot Smith.
-- Added support for irregular inflexions (from patch #12384). Thanks
+- Added support for irregular inflexions (from patch #12384). Thanks
to Juan Ignacio Pumarino.
- Added hidding of magic fields (--hide-magic) (from patch #13351)
Thanks to Hajime Baba.
@@ -31,17 +31,17 @@ Version 0.3.4 (apr 12 2007)
(don't try to get content columns, bug #10033)
- Add verbose mode
- More code cleanup.
-- Using an internal representation and then
+- Using an internal representation and then
generating the DOT output. This will allow to
add more output formats in the future.
Version 0.3.3 (apr 10 2007)
-- Code cleanup
+- Code cleanup
Version 0.3.2 (apr 9 2007)
-- Disable STDOUT when loading applications classes, avoiding
+- Disable STDOUT when loading applications classes, avoiding
messing up the DOT output.
(Thanks to Sebastien Auvray, http://tnlessone.wordpress.com/)
@@ -51,7 +51,7 @@ Version 0.3.1 (apr 9 2007)
Version 0.3.0 (apr 9 2007)
-- Major code rewrite
+- Major code rewrite
(More OO style)
- Using Ruby's optparse to parse commandline options
- Added flags for including (excluding) controllers methods
@@ -64,7 +64,7 @@ Version 0.2.0 (apr 8 2007)
- Differentiate classes from modules
- Added "-m" flag for considering modules
- Draw double-headed arrows for habtm and has_many, :through associations
-- Fix inheritance support for non ActiveRecord::Base classes on model
+- Fix inheritance support for non ActiveRecord::Base classes on model
diagrams
View
22 README
@@ -1,6 +1,6 @@
-= RailRoad
+= RailRoad
-RailRoad generates models and controllers diagrams in DOT language for a
+RailRoad generates models and controllers diagrams in DOT language for a
Rails application.
@@ -12,7 +12,7 @@ graphic. Model diagrams are intended to be processed using dot and
controller diagrams are best processed using neato.
railroad [options] command
-
+
== Options
Common options:
@@ -55,9 +55,9 @@ Other options:
== Examples
- railroad -o models.dot -M
+ railroad -o models.dot -M
Produces a models diagram to the file 'models.dot'
- railroad -a -i -o full_models.dot -M
+ railroad -a -i -o full_models.dot -M
Models diagram with all classes showing inheritance relations
railroad -M | dot -Tsvg > models.svg
Model diagram in SVG format
@@ -88,7 +88,7 @@ the following:
Important: There is a bug in Graphviz tools when generating SVG files that
cause a text overflow. You can solve this problem editing (with a text
editor, not a graphical SVG editor) the file and replacing around line 12
-"font-size:14.00;" by "font-size:11.00;", or by issuing the following command
+"font-size:14.00;" by "font-size:11.00;", or by issuing the following command
(see "man sed"):
sed -i 's/font-size:14.00/font-size:11.00/g' file.svg
@@ -108,15 +108,15 @@ In your Rails application, put the following rake tasks into 'lib/task/diagrams.
task :models do
sh "railroad -i -l -a -m -M | dot -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/models.svg"
end
-
+
task :controllers do
sh "railroad -i -l -C | neato -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/controllers.svg"
end
end
-
+
task :diagrams => %w(diagram:models diagram:controllers)
end
-
+
Then, 'rake doc:diagrams' produces 'doc/models.svg' and 'doc/controllers.svg'.
= Requirements
@@ -135,11 +135,11 @@ http://railroad.rubyforge.org
= License
RailRoad is distributed under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2 of the
+as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
= Author
-Javier Smaldone
+Javier Smaldone
(javier -at- smaldone -dot- com -dot- ar, http://blog.smaldone.com.ar )
@@ -11,7 +11,7 @@ class AasmDiagram < AppDiagram
def initialize(options)
#options.exclude.map! {|e| e = "app/models/" + e}
- super options
+ super options
@graph.diagram_type = 'Models'
# Processed habtm associations
@habtm = []
@@ -20,23 +20,23 @@ def initialize(options)
# Process model files
def generate
STDERR.print "Generating AASM diagram\n" if @options.verbose
- 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.each do |f|
+ files.each do |f|
process_class extract_class_name(f).constantize
end
end
-
+
private
-
+
# Load model classes
def load_classes
begin
disable_stdout
files = Dir.glob("app/models/**/*.rb")
files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
- files -= @options.exclude
+ files -= @options.exclude
files.each {|m| require m }
enable_stdout
rescue LoadError
@@ -48,28 +48,28 @@ def load_classes
# Process a model class
def process_class(current_class)
-
+
STDERR.print "\tProcessing #{current_class}\n" if @options.verbose
-
+
# Only interested in acts_as_state_machine models.
return unless current_class.respond_to?'states'
-
+
node_attribs = []
node_type = 'aasm'
-
+
current_class.states.each do |state_name|
state = current_class.read_inheritable_attribute(:states)[state_name]
node_shape = (current_class.initial_state === state_name) ? ", peripheries = 2" : ""
node_attribs << "#{current_class.name.downcase}_#{state_name} [label=#{state_name} #{node_shape}];"
end
@graph.add_node [node_type, current_class.name, node_attribs]
-
+
current_class.read_inheritable_attribute(:transition_table).each do |event_name, event|
event.each do |transition|
@graph.add_edge [
- 'event',
- current_class.name.downcase + "_" + transition.from.to_s,
- current_class.name.downcase + "_" + transition.to.to_s,
+ 'event',
+ current_class.name.downcase + "_" + transition.from.to_s,
+ current_class.name.downcase + "_" + transition.to.to_s,
event_name.to_s
]
end
@@ -30,29 +30,29 @@ def print
exit 2
end
end
-
- if @options.xmi
+
+ if @options.xmi
STDERR.print "Generating XMI diagram\n" if @options.verbose
STDOUT.print @graph.to_xmi
else
STDERR.print "Generating DOT graph\n" if @options.verbose
- STDOUT.print @graph.to_dot
+ STDOUT.print @graph.to_dot
end
if @options.output
STDOUT.reopen(old_stdout)
end
end # print
- private
+ private
# Prevents Rails application from writing to STDOUT
def disable_stdout
@old_stdout = STDOUT.dup
STDOUT.reopen(PLATFORM =~ /mswin/ ? "NUL" : "/dev/null")
end
- # Restore STDOUT
+ # Restore STDOUT
def enable_stdout
STDOUT.reopen(@old_stdout)
end
@@ -6,7 +6,7 @@
# RailRoad controllers diagram
class ControllersDiagram < AppDiagram
-
+
def initialize(options)
#options.exclude.map! {|e| "app/controllers/" + e}
super options
@@ -24,7 +24,7 @@ def generate
# ApplicationController's file is 'application.rb'
class_name += 'Controller' if class_name == 'Application'
process_class class_name.constantize
- end
+ end
end # generate
private
@@ -34,7 +34,7 @@ def load_classes
begin
disable_stdout
# ApplicationController must be loaded first
- require "app/controllers/application.rb"
+ require "app/controllers/application.rb"
files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
files.each {|c| require c }
enable_stdout
@@ -52,10 +52,10 @@ def process_class(current_class)
if @options.brief
@graph.add_node ['controller-brief', current_class.name]
- elsif current_class.is_a? Class
+ elsif current_class.is_a? Class
# Collect controller's methods
- node_attribs = {:public => [],
- :protected => [],
+ node_attribs = {:public => [],
+ :protected => [],
:private => []}
current_class.public_instance_methods(false).sort.each { |m|
node_attribs[:public] << m
@@ -64,15 +64,15 @@ def process_class(current_class)
node_attribs[:protected] << m
} unless @options.hide_protected
current_class.private_instance_methods(false).sort.each { |m|
- node_attribs[:private] << m
+ node_attribs[:private] << m
} unless @options.hide_private
@graph.add_node ['controller', current_class.name, node_attribs]
elsif @options.modules && current_class.is_a?(Module)
@graph.add_node ['module', current_class.name]
end
# Generate the inheritance edge (only for ApplicationControllers)
- if @options.inheritance &&
+ if @options.inheritance &&
(ApplicationController.subclasses.include? current_class.name)
@graph.add_edge ['is-a', current_class.superclass.name, current_class.name]
end
@@ -13,7 +13,7 @@ def initialize
@show_label = false
@nodes = []
@edges = []
- end
+ end
def add_node(node)
@nodes << node
@@ -22,7 +22,7 @@ def add_node(node)
def add_edge(edge)
@edges << edge
end
-
+
def diagram_type= (type)
@diagram_type = type
end
@@ -39,7 +39,7 @@ def to_dot
@edges.map{|e| dot_edge e[0], e[1], e[2], e[3]}.join +
dot_footer
end
-
+
# Generate XMI diagram (not yet implemented)
def to_xmi
STDERR.print "Sorry. XMI output not yet implemented.\n\n"
@@ -60,12 +60,12 @@ def dot_header
def dot_footer
return "}\n"
end
-
+
# Build diagram label
def dot_label
return "\t_diagram_info [shape=\"plaintext\", " +
"label=\"#{@diagram_type} diagram\\l" +
- "Date: #{Time.now.strftime "%b %d %Y - %H:%M"}\\l" +
+ "Date: #{Time.now.strftime "%b %d %Y - %H:%M"}\\l" +
"Migration version: " +
"#{ActiveRecord::Migrator.current_version}\\l" +
"Generated by #{APP_HUMAN_NAME} #{APP_VERSION.join('.')}"+
@@ -82,19 +82,19 @@ def dot_node(type, name, attributes=nil)
when 'model-brief'
options = ''
when 'class'
- options = 'shape=record, label="{' + name + '|}"'
+ options = 'shape=record, label="{' + name + '|}"'
when 'class-brief'
- options = 'shape=box'
+ options = 'shape=box'
when 'controller'
options = 'shape=Mrecord, label="{' + name + '|'
public_methods = attributes[:public].join('\l')
protected_methods = attributes[:protected].join('\l')
private_methods = attributes[:private].join('\l')
- options += public_methods + '\l|' + protected_methods + '\l|' +
+ options += public_methods + '\l|' + protected_methods + '\l|' +
private_methods + '\l'
options += '}"'
when 'controller-brief'
- options = ''
+ options = ''
when 'module'
options = 'shape=box, style=dotted, label="' + name + '"'
when 'aasm'
@@ -113,7 +113,7 @@ def dot_edge(type, from, to, name = '')
options += 'arrowtail=odot, arrowhead=dot, dir=both'
when 'one-many'
#options += 'taillabel="n"'
- options += 'arrowtail=crow, arrowhead=dot, dir=both'
+ options += 'arrowtail=crow, arrowhead=dot, dir=both'
when 'many-many'
#options += 'taillabel="n", headlabel="n", arrowtail="normal"'
options += 'arrowtail=crow, arrowhead=crow, dir=both'
@@ -129,5 +129,5 @@ def dot_edge(type, from, to, name = '')
def quote(name)
'"' + name.to_s + '"'
end
-
+
end # class DiagramGraph
Oops, something went wrong.