Class: ControllersDiagram

Inherits:
AppDiagram show all
Defined in:
lib/railroad/controllers_diagram.rb

Overview

RailRoad controllers diagram

Constant Summary collapse

APP_CONTROLLER =

as of Rails 2.3 the file is no longer application.rb but instead application_controller.rb

File.exist?('app/controllers/application.rb') ? 'app/controllers/application.rb' : 'app/controllers/application_controller.rb'

Instance Method Summary collapse

Methods inherited from AppDiagram

#print, #process

Constructor Details

#initialize(options = OptionsStruct.new) ⇒ ControllersDiagram

Returns a new instance of ControllersDiagram.



16
17
18
19
20
# File 'lib/railroad/controllers_diagram.rb', line 16

def initialize(options = OptionsStruct.new)
  #options.exclude.map! {|e| "app/controllers/" + e}
  super options
  @graph.diagram_type = 'Controllers'
end

Instance Method Details

#generateObject

Process controller files



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/railroad/controllers_diagram.rb', line 23

def generate
  STDERR.print "Generating controllers diagram\n" if @options.verbose
  files = get_files
  # 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' in Rails < 2.3
    class_name += 'Controller' if class_name == 'Application'
    begin
      process_class class_name.constantize
    rescue Exception
      STDERR.print "Warning: exception #{$!} raised while trying to load controller class #{f}"
    end
  end 
end

#get_files(prefix = '') ⇒ Object

generate



40
41
42
43
44
# File 'lib/railroad/controllers_diagram.rb', line 40

def get_files(prefix ='')
  files = !@options.specify.empty? ? Dir.glob(@options.specify) : Dir.glob(prefix << "app/controllers/**/*_controller.rb")
  files -= Dir.glob(@options.exclude)
  files
end