Permalink
Browse files

add: support for rails v2.3

  • Loading branch information...
1 parent 5cc0b7d commit 6ec975d13e6b3e7f85428a1a5747366b26258a48 @peterhoeg peterhoeg committed May 15, 2009
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/railroad/controllers_diagram.rb
View
11 lib/railroad/controllers_diagram.rb
@@ -9,6 +9,10 @@
# RailRoad controllers diagram
class ControllersDiagram < AppDiagram
+ # as of Rails 2.3 the file is no longer application.rb but instead
+ # application_controller.rb
+ APP_CONTROLLER = File.exist?('app/controllers/application.rb') ? 'app/controllers/application.rb' : 'app/controllers/application_controller.rb'
+
def initialize(options)
#options.exclude.map! {|e| "app/controllers/" + e}
super options
@@ -20,10 +24,11 @@ def generate
STDERR.print "Generating controllers diagram\n" if @options.verbose
files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
- files << 'app/controllers/application.rb'
+ # only add APP_CONTROLLER if it isn't already included from the glob above
+ files << APP_CONTROLLER unless files.include? APP_CONTROLLER
files.each do |f|
class_name = extract_class_name(f)
- # ApplicationController's file is 'application.rb'
+ # ApplicationController's file is 'application.rb' in Rails < 2.3
class_name += 'Controller' if class_name == 'Application'
process_class class_name.constantize
end
@@ -36,7 +41,7 @@ def load_classes
begin
disable_stdout
# ApplicationController must be loaded first
- require "app/controllers/application.rb"
+ require APP_CONTROLLER
files = Dir.glob("app/controllers/**/*_controller.rb") - @options.exclude
files.each {|c| require c }
enable_stdout

0 comments on commit 6ec975d

Please sign in to comment.