railroad 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/ChangeLog +7 -0
  2. data/lib/railroad +39 -11
  3. data/rake.gemspec +12 -12
  4. metadata +3 -1
data/ChangeLog CHANGED
@@ -1,6 +1,13 @@
1
+ Version 0.3.2 (apr 9 2007)
2
+ - Disable STDOUT when loading applications classes, avoiding
3
+ messing up the DOT output.
4
+ (Thanks to Sebastien Auvray, http://tnlessone.wordpress.com/)
5
+
6
+
1
7
  Version 0.3.1 (apr 9 2007)
2
8
  - Release again for fix an error in .gem file
3
9
 
10
+
4
11
  Version 0.3.0 (apr 9 2007)
5
12
  - Major code rewrite
6
13
  (More OO style)
data/lib/railroad CHANGED
@@ -16,15 +16,17 @@
16
16
 
17
17
  APP_NAME = "railroad"
18
18
  APP_HUMAN_NAME = "RailRoad"
19
- APP_VERSION = [0,3,1]
19
+ APP_VERSION = [0,3,2]
20
20
  COPYRIGHT = "Copyright (C) 2007 Javier Smaldone"
21
21
 
22
22
 
23
+ # Command line options parser
23
24
  class OptionsParser
24
25
 
25
26
  require 'optparse'
26
27
  require 'ostruct'
27
28
 
29
+ # Parse arguments from command line
28
30
  def self.parse(args)
29
31
 
30
32
  options = OpenStruct.new
@@ -101,7 +103,7 @@ class OptionsParser
101
103
  opts.separator "Commands (you must supply one of these):"
102
104
  opts.on("-M", "--models", "Generate models diagram") do |c|
103
105
  if options.command == 'controllers'
104
- $stderr.print "Error: Can't generate models AND controllers diagram\n\n"
106
+ STDERR.print "Error: Can't generate models AND controllers diagram\n\n"
105
107
  exit 1
106
108
  else
107
109
  options.command = 'models'
@@ -109,7 +111,7 @@ class OptionsParser
109
111
  end
110
112
  opts.on("-C", "--controllers", "Generate controllers diagram") do |c|
111
113
  if options.command == 'models'
112
- $stderr.print "Error: Can't generate models AND controllers diagram\n\n"
114
+ STDERR.print "Error: Can't generate models AND controllers diagram\n\n"
113
115
  exit 1
114
116
  else
115
117
  options.command = 'controllers'
@@ -139,13 +141,14 @@ class OptionsParser
139
141
  private
140
142
 
141
143
  def self.option_error(msg, opts)
142
- $stderr.print "Error: #{msg}\n\n #{opts}\n"
144
+ STDERR.print "Error: #{msg}\n\n #{opts}\n"
143
145
  exit 1
144
146
  end
145
147
 
146
148
  end # class OptionsParser
147
149
 
148
150
 
151
+ # Root class for RailRoad diagrams
149
152
  class AppDiagram
150
153
 
151
154
  def initialize(options)
@@ -160,6 +163,18 @@ class AppDiagram
160
163
  '"' + name + '"'
161
164
  end
162
165
 
166
+ # Prevents Rails application from writing to STDOUT
167
+ def disable_stdout
168
+ @old_stdout = STDOUT.dup
169
+ STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
170
+ end
171
+
172
+ # Restore STDOUT
173
+ def enable_stdout
174
+ STDOUT.reopen(@old_stdout)
175
+ end
176
+
177
+
163
178
  # Print diagram label
164
179
  def print_info(type)
165
180
  print "\t_diagram_info [shape=\"plaintext\", label=\"Diagram: #{type}\\l" +
@@ -169,6 +184,7 @@ class AppDiagram
169
184
  ", fontsize=14]\n"
170
185
  end
171
186
 
187
+ # Print error when loading application classes
172
188
  def print_error(type)
173
189
  STDERR.print "Error loading #{type}.\n (Are you running " +
174
190
  "#{APP_NAME} on the aplication's root directory?)\n\n"
@@ -177,8 +193,11 @@ class AppDiagram
177
193
  # Load Rails application's environment
178
194
  def load_environment
179
195
  begin
196
+ disable_stdout
180
197
  require "config/environment"
198
+ enable_stdout
181
199
  rescue LoadError
200
+ enable_stdout
182
201
  print_error "app environment"
183
202
  raise
184
203
  end
@@ -187,6 +206,7 @@ class AppDiagram
187
206
  end # class AppDiagram
188
207
 
189
208
 
209
+ # RailRoad models diagram
190
210
  class ModelsDiagram < AppDiagram
191
211
 
192
212
  # Generate models diagram
@@ -218,8 +238,11 @@ class ModelsDiagram < AppDiagram
218
238
  # Load model classes
219
239
  def load_classes
220
240
  begin
241
+ disable_stdout
221
242
  Dir.glob("app/models/**/*.rb") {|m| require m }
243
+ enable_stdout
222
244
  rescue LoadError
245
+ enable_stdout
223
246
  print_error "model classes"
224
247
  raise
225
248
  end
@@ -316,6 +339,7 @@ class ModelsDiagram < AppDiagram
316
339
  end # class ModelsDiagram
317
340
 
318
341
 
342
+ # RailRoad controllers diagram
319
343
  class ControllersDiagram < AppDiagram
320
344
 
321
345
  # Generate controllers diagram
@@ -353,12 +377,15 @@ class ControllersDiagram < AppDiagram
353
377
  # Load controller classes
354
378
  def load_classes
355
379
  begin
380
+ disable_stdout
356
381
  # ApplicationController must be loaded first
357
382
  require "app/controllers/application.rb"
358
383
  Dir.glob("app/controllers/**/*_controller.rb") do |c|
359
384
  require c
360
385
  end
386
+ enable_stdout
361
387
  rescue LoadError
388
+ enable_stdout
362
389
  print_error "controller classes"
363
390
  raise
364
391
  end
@@ -366,6 +393,7 @@ class ControllersDiagram < AppDiagram
366
393
 
367
394
  # Proccess controller class
368
395
  def process_class(current_class)
396
+
369
397
  # Print the node
370
398
  if @options.brief
371
399
  print "\t#{node(current_class.name)}\n"
@@ -411,23 +439,23 @@ if options.command == 'models'
411
439
  elsif options.command == 'controllers'
412
440
  diagram = ControllersDiagram.new options
413
441
  else
414
- $stderr.print "Error: You must supply a command\n" +
415
- " (try #{APP_NAME} -h)\n\n"
442
+ STDERR.print "Error: You must supply a command\n" +
443
+ " (try #{APP_NAME} -h)\n\n"
416
444
  exit 1
417
445
  end
418
446
 
419
447
  if options.output
420
- old_stdout = $stdout
448
+ old_stdout = STDOUT.dup
421
449
  begin
422
- $stdout = File.open(options.output, "w")
450
+ STDOUT.reopen(options.output)
423
451
  rescue
424
- $stderr.print "Error: Cannot write to #{options.output}\n\n"
452
+ STDERR.print "Error: Cannot write to #{options.output}\n\n"
425
453
  exit 2
426
454
  end
427
455
  end
428
456
 
429
457
  diagram.generate
430
458
 
431
- if options.out
432
- $stdout = old_stdout
459
+ if options.output
460
+ STDOUT.reopen(old_stdout)
433
461
  end
data/rake.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  require 'rubygems'
2
2
  SPEC = Gem::Specification.new do |s|
3
- s.name = "railroad"
4
- s.version = "0.3.1"
5
- s.author = "Javier Smaldone"
6
- s.email = "javier@smaldone.com.ar"
7
- s.homepage = "http://railroad.rubyforge.org"
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = "A DOT diagram generator for Ruby on Rail applications"
10
- s.files = ["ChangeLog", "COPYING", "rake.gemspec"]
11
- s.bindir = "lib"
12
- s.executables = ["railroad"]
3
+ s.name = "railroad"
4
+ s.version = "0.3.2"
5
+ s.author = "Javier Smaldone"
6
+ s.email = "javier@smaldone.com.ar"
7
+ s.homepage = "http://railroad.rubyforge.org"
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "A DOT diagram generator for Ruby on Rail applications"
10
+ s.files = ["lib/railroad", "ChangeLog", "COPYING", "rake.gemspec"]
11
+ s.bindir = "lib"
12
+ s.executables = ["railroad"]
13
13
  s.default_executable = "railroad"
14
- s.has_rdoc = true
15
- s.extra_rdoc_files = ["README"]
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = ["README", "lib/railroad"]
16
16
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: railroad
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.1
6
+ version: 0.3.2
7
7
  date: 2007-04-09 00:00:00 -03:00
8
8
  summary: A DOT diagram generator for Ruby on Rail applications
9
9
  require_paths:
@@ -29,6 +29,7 @@ post_install_message:
29
29
  authors:
30
30
  - Javier Smaldone
31
31
  files:
32
+ - lib/railroad
32
33
  - ChangeLog
33
34
  - COPYING
34
35
  - rake.gemspec
@@ -39,6 +40,7 @@ rdoc_options: []
39
40
 
40
41
  extra_rdoc_files:
41
42
  - README
43
+ - lib/railroad
42
44
  executables:
43
45
  - railroad
44
46
  extensions: []