dmattes-railroad_xing 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ # A factory that determines if railroad is running in an application
2
+ # framework and if so, returns a "framework" object that handles interacting
3
+ # with the framework. If the factory can not determine find a framework,
4
+ # then the factory will return nil.
5
+ #
6
+ # === Usage
7
+ #
8
+ # framework = FrameworkFactory.getFramework
9
+ #
10
+ # Dec 2008 - Roy Wright
11
+ # created to support multiple frameworks
12
+ #
13
+ class FrameworkFactory
14
+
15
+ # the factory the returns a "framework" object or nil
16
+ def self.getFramework
17
+ framework = nil
18
+ if File.exist? 'merb'
19
+ require 'railroad/merb_framework'
20
+ framework = MerbFramework.new
21
+ end
22
+ if File.exist? 'script/server'
23
+ require 'railroad/rails_framework'
24
+ framework = RailsFramework.new
25
+ end
26
+ framework
27
+ end
28
+
29
+ private
30
+
31
+ # prevent instantiation
32
+ def initialize
33
+ end
34
+ end
35
+
@@ -0,0 +1,55 @@
1
+ # A class that encapsulates the interaction with the Merb framework.
2
+ #
3
+ # Note, will use the 'test' envirnoment and database.
4
+ #
5
+ # Warning, will automigrate the 'test' database
6
+ #
7
+ # Dec 2008 - Roy Wright
8
+ # created to support the Merb application framework
9
+ #
10
+ class MerbFramework
11
+ attr_reader :name, :migration_version
12
+
13
+ # enter the merb 'test' environment
14
+ def initialize
15
+ require 'merb-core'
16
+ Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
17
+ case Merb::Config[:merb_orm]
18
+ when :datamapper: DataMapper.auto_migrate!
19
+ when :activerecord: ActiveRecord::Migrator.migrate(File.expand_path(File.dirname(__FILE__) + "/schema/migrations"))
20
+ end
21
+ @name = 'Merb'
22
+ @migration_version = nil
23
+ end
24
+
25
+ # is the given class a subclass of the application controller?
26
+ def is_application_subclass?(klass)
27
+ (Application.subclasses_list.include? klass.name)
28
+ end
29
+
30
+ # get the controller's files returning the application controller first in returned array
31
+ def get_controller_files(options)
32
+ files = []
33
+ files << 'app/controllers/application.rb'
34
+ files += Dir.glob("app/controllers/**/*.rb") - options.exclude
35
+ files.uniq
36
+ end
37
+
38
+ # Extract class name from filename
39
+ def extract_class_name(filename)
40
+ # handle subdirectories as modules
41
+ # i.e., app/controllers/foo/bar.rb => Foo::Bar
42
+ if filename =~ /^app\/controllers\/(.*)\.rb$/
43
+ class_name = $1.split('/').collect {|part| part.camel_case}.join('::')
44
+ else
45
+ class_name = File.basename(filename).chomp(".rb").camel_case
46
+ end
47
+ class_name
48
+ end
49
+
50
+ # convert the give string to a constant
51
+ def constantize(str)
52
+ Object.full_const_get(str)
53
+ end
54
+
55
+ end
@@ -0,0 +1,25 @@
1
+ require 'railroad/ar_model'
2
+ require 'railroad/dm_model'
3
+
4
+ # A factory for discovering the ORM being used that will then return the
5
+ # corresponding "model" that will be used to interact with the ORM. Will
6
+ # return nil if unable to discover a supported ORM.
7
+ #
8
+ # Dec 2008 - Roy Wright
9
+ # created to support multiple ORMs
10
+ #
11
+ class ModelFactory
12
+ def self.getModel(klass, options)
13
+ model = nil
14
+ model = AR_Model.new(klass, options) if klass.respond_to?'reflect_on_all_associations'
15
+ model = DM_Model.new(klass, options) if klass.respond_to?'relationships'
16
+ model
17
+ end
18
+
19
+ private
20
+
21
+ # prevent instantiation
22
+ def initialize
23
+ end
24
+ end
25
+
@@ -0,0 +1,86 @@
1
+ # RailRoad - RoR diagrams generator
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
+ # Dec 2008 - Roy Wright
8
+ # modified to support multiple application frameworks and ORMs
9
+
10
+ require 'railroad/app_diagram'
11
+ require 'railroad/model_factory'
12
+
13
+ # RailRoad models diagram
14
+ class ModelsDiagram < AppDiagram
15
+
16
+ def initialize(options)
17
+ #options.exclude.map! {|e| "app/models/" + e}
18
+ super options
19
+ @graph.diagram_type = 'Models'
20
+ end
21
+
22
+ # Process model files
23
+ def generate
24
+ STDERR.print "Generating models diagram\n" if @options.verbose
25
+ files = Dir.glob("app/models/**/*.rb")
26
+ files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
27
+ files -= @options.exclude
28
+ files.each do |f|
29
+ process_class constantize(extract_class_name(f))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # Load model classes
36
+ def load_classes
37
+ begin
38
+ disable_stdout
39
+ files = Dir.glob("app/models/**/*.rb")
40
+ files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models
41
+ files -= @options.exclude
42
+ files.each {|m| require m }
43
+ enable_stdout
44
+ rescue LoadError
45
+ enable_stdout
46
+ print_error "model classes"
47
+ raise
48
+ end
49
+ end # load_classes
50
+
51
+ # Process a model class
52
+ def process_class(current_class)
53
+
54
+ STDERR.print "\tProcessing #{current_class}\n" if @options.verbose
55
+
56
+ model = ModelFactory.getModel(current_class, @options)
57
+ node_attribs = []
58
+ edges = []
59
+ nodes = []
60
+ if @options.brief || (!model.nil? && model.abstract?)
61
+ node_type = 'model-brief'
62
+ else
63
+ node_type = 'model'
64
+ node_attribs += model.attributes unless model.nil?
65
+ end
66
+ nodes << [node_type, current_class.name, node_attribs]
67
+
68
+ if !model.nil?
69
+ edges += model.edges
70
+ # Only consider meaningful inheritance relations classes
71
+ if @options.inheritance && model.meaningful?
72
+ edges << ['is-a', current_class.superclass.name, current_class.name]
73
+ end
74
+ elsif @options.all && (current_class.is_a? Class)
75
+ # Not database model
76
+ node_type = @options.brief ? 'class-brief' : 'class'
77
+ nodes << [node_type, current_class.name]
78
+ edges << ['is-a', current_class.superclass.name, current_class.name]
79
+ elsif @options.modules && (current_class.is_a? Module)
80
+ nodes << ['module', current_class.name]
81
+ end
82
+ nodes.compact.each {|node| @graph.add_node node}
83
+ edges.compact.each {|edge| @graph.add_edge edge}
84
+ end # process_class
85
+
86
+ end # class ModelsDiagram
@@ -0,0 +1,173 @@
1
+ # RailRoad - RoR diagrams generator
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
+ require 'ostruct'
8
+
9
+ # RailRoad command line options parser
10
+ class OptionsStruct < OpenStruct
11
+
12
+ require 'optparse'
13
+
14
+ def initialize
15
+ init_options = { :all => false,
16
+ :brief => false,
17
+ :exclude => [],
18
+ :inheritance => false,
19
+ :join => false,
20
+ :label => false,
21
+ :modules => false,
22
+ :hide_magic => false,
23
+ :show_magic => false,
24
+ :hide_types => false,
25
+ :hide_public => false,
26
+ :hide_protected => false,
27
+ :hide_private => false,
28
+ :plugins_models => false,
29
+ :root => '',
30
+ :transitive => false,
31
+ :verbose => false,
32
+ :xmi => false,
33
+ :command => '' }
34
+ super(init_options)
35
+ end # initialize
36
+
37
+ def parse(args)
38
+ @opt_parser = OptionParser.new do |opts|
39
+ opts.banner = "Usage: #{APP_NAME} [options] command"
40
+ opts.separator ""
41
+ opts.separator "Common options:"
42
+ opts.on("-b", "--brief", "Generate compact diagram",
43
+ " (no attributes nor methods)") do |b|
44
+ self.brief = b
45
+ end
46
+ opts.on("-e", "--exclude file1[,fileN]", Array, "Exclude given files") do |list|
47
+ self.exclude = list
48
+ end
49
+ opts.on("-i", "--inheritance", "Include inheritance relations") do |i|
50
+ self.inheritance = i
51
+ end
52
+ opts.on("-l", "--label", "Add a label with diagram information",
53
+ " (type, date, migration, version)") do |l|
54
+ self.label = l
55
+ end
56
+ opts.on("-o", "--output FILE", "Write diagram to file FILE") do |f|
57
+ self.output = f
58
+ end
59
+ opts.on("-r", "--root PATH", "Set PATH as the application root") do |r|
60
+ self.root = r
61
+ end
62
+ opts.on("-v", "--verbose", "Enable verbose output",
63
+ " (produce messages to STDOUT)") do |v|
64
+ self.verbose = v
65
+ end
66
+ opts.on("-x", "--xmi", "Produce XMI instead of DOT",
67
+ " (for UML tools)") do |x|
68
+ self.xmi = x
69
+ end
70
+ opts.separator ""
71
+ opts.separator "Models diagram options:"
72
+ opts.on("-a", "--all", "Include all models",
73
+ " (not only ActiveRecord::Base derived)") do |a|
74
+ self.all = a
75
+ end
76
+ opts.on("--hide-magic", "Hide magic field names") do |h|
77
+ self.hide_magic = h
78
+ end
79
+ opts.on("--show-magic", "Show magic field names") do |h|
80
+ self.show_magic = h
81
+ end
82
+ opts.on("--hide-types", "Hide attributes type") do |h|
83
+ self.hide_types = h
84
+ end
85
+ opts.on("-j", "--join", "Concentrate edges") do |j|
86
+ self.join = j
87
+ end
88
+ opts.on("-m", "--modules", "Include modules") do |m|
89
+ self.modules = m
90
+ end
91
+ opts.on("-p", "--plugins-models", "Include plugins models") do |p|
92
+ self.plugins_models = p
93
+ end
94
+ opts.on("-t", "--transitive", "Include transitive associations",
95
+ "(through inheritance)") do |t|
96
+ self.transitive = t
97
+ end
98
+ opts.separator ""
99
+ opts.separator "Controllers diagram options:"
100
+ opts.on("--hide-public", "Hide public methods") do |h|
101
+ self.hide_public = h
102
+ end
103
+ opts.on("--hide-protected", "Hide protected methods") do |h|
104
+ self.hide_protected = h
105
+ end
106
+ opts.on("--hide-private", "Hide private methods") do |h|
107
+ self.hide_private = h
108
+ end
109
+ opts.separator ""
110
+ opts.separator "Other options:"
111
+ opts.on("-h", "--help", "Show this message") do
112
+ STDOUT.print "#{opts}\n"
113
+ exit
114
+ end
115
+ opts.on("--version", "Show version and copyright") do
116
+ STDOUT.print "#{APP_HUMAN_NAME} version #{APP_VERSION.join('.')}\n\n" +
117
+ "#{COPYRIGHT}\nThis is free software; see the source " +
118
+ "for copying conditions.\n\n"
119
+ exit
120
+ end
121
+ opts.separator ""
122
+ opts.separator "Commands (you must supply one of these):"
123
+ opts.on("-M", "--models", "Generate models diagram") do |c|
124
+ if self.command != ''
125
+ STDERR.print "Error: Can only generate one diagram type\n\n"
126
+ exit 1
127
+ else
128
+ self.command = 'models'
129
+ end
130
+ end
131
+ opts.on("-C", "--controllers", "Generate controllers diagram") do |c|
132
+ if self.command != ''
133
+ STDERR.print "Error: Can only generate one diagram type\n\n"
134
+ exit 1
135
+ else
136
+ self.command = 'controllers'
137
+ end
138
+ end
139
+ # From Ana Nelson's patch
140
+ opts.on("-A", "--aasm", "Generate \"acts as state machine\" diagram") do |c|
141
+ if self.command == 'controllers'
142
+ STDERR.print "Error: Can only generate one diagram type\n\n"
143
+ exit 1
144
+ else
145
+ self.command = 'aasm'
146
+ end
147
+ end
148
+ opts.separator ""
149
+ opts.separator "For bug reporting and additional information, please see:"
150
+ opts.separator "http://railroad.rubyforge.org/"
151
+ end # do
152
+
153
+ begin
154
+ @opt_parser.parse!(args)
155
+ rescue OptionParser::AmbiguousOption
156
+ option_error "Ambiguous option"
157
+ rescue OptionParser::InvalidOption
158
+ option_error "Invalid option"
159
+ rescue OptionParser::InvalidArgument
160
+ option_error "Invalid argument"
161
+ rescue OptionParser::MissingArgument
162
+ option_error "Missing argument"
163
+ end
164
+ end # parse
165
+
166
+ private
167
+
168
+ def option_error(msg)
169
+ STDERR.print "Error: #{msg}\n\n #{@opt_parser}\n"
170
+ exit 1
171
+ end
172
+
173
+ end # class OptionsStruct
@@ -0,0 +1,54 @@
1
+ # A class that encapsulates the interaction with the Rails framework.
2
+ #
3
+ # Dec 2008 - Roy Wright
4
+ # created to support the Rails application framework
5
+ #
6
+ class RailsFramework
7
+ attr_reader :name, :migration_version
8
+
9
+ def initialize
10
+ require "config/environment"
11
+ @name = 'Rails'
12
+ @migration_version = ActiveRecord::Migrator.current_version
13
+ end
14
+
15
+ # is the given class a subclass of the application controller?
16
+ def is_application_subclass?(klass)
17
+ (ApplicationController.subclasses.include? klass.name)
18
+ end
19
+
20
+ # get the controller's files returning the application controller first in returned array
21
+ def get_controller_files(options)
22
+ files = []
23
+ files << 'app/controllers/application_controller.rb' if File.exist?('app/controllers/application_controller.rb')
24
+ files << 'app/controllers/application.rb' if File.exist?('app/controllers/application.rb')
25
+ files += Dir.glob("app/controllers/**/*_controller.rb") - options.exclude
26
+ files.uniq
27
+ end
28
+
29
+ # Extract class name from filename
30
+ def extract_class_name(filename)
31
+ # handle subdirectories as modules
32
+ # i.e., app/controllers/foo/bar.rb => Foo::Bar
33
+ if filename =~ /^app\/controllers\/(.*)\.rb$/
34
+ class_name = $1.split('/').collect {|part| part.camelize}.join('::')
35
+ elsif filename =~ /^app\/models\/(.*)\.rb$/
36
+ class_name = $1.split('/').collect {|part| part.camelize}.join('::')
37
+ else
38
+ class_name = File.basename(filename).chomp(".rb").camelize
39
+ end
40
+
41
+ if filename == 'app/controllers/application.rb'
42
+ # ApplicationController's file is 'application.rb'
43
+ class_name += 'Controller' if class_name == 'Application'
44
+ end
45
+ class_name
46
+ end
47
+
48
+ # convert the give string to a constant
49
+ def constantize(str)
50
+ str.constantize
51
+ end
52
+
53
+ end
54
+
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dmattes-railroad_xing}
8
+ s.version = "0.5.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roy Wright, modified by Daniel Mattes"]
12
+ s.date = %q{2010-01-10}
13
+ s.default_executable = %q{railroad}
14
+ s.email = %q{dm@actsasblog.de}
15
+ s.executables = ["railroad"]
16
+ s.extra_rdoc_files = [
17
+ "ChangeLog",
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "AUTHORS",
23
+ "COPYING",
24
+ "ChangeLog",
25
+ "INSTALL",
26
+ "README",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/railroad",
30
+ "lib/railroad/aasm_diagram.rb",
31
+ "lib/railroad/app_diagram.rb",
32
+ "lib/railroad/ar_model.rb",
33
+ "lib/railroad/controllers_diagram.rb",
34
+ "lib/railroad/diagram_graph.rb",
35
+ "lib/railroad/dm_model.rb",
36
+ "lib/railroad/framework_factory.rb",
37
+ "lib/railroad/merb_framework.rb",
38
+ "lib/railroad/model_factory.rb",
39
+ "lib/railroad/models_diagram.rb",
40
+ "lib/railroad/options_struct.rb",
41
+ "lib/railroad/rails_framework.rb",
42
+ "railroad_xing.gemspec"
43
+ ]
44
+ s.homepage = %q{http://github.com/dmattes/railroad_xing}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.5}
48
+ s.summary = %q{A DOT diagram generator for Ruby web applications (Rails, Merb)}
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ else
56
+ end
57
+ else
58
+ end
59
+ end