Class: ControllersDiagram
- Inherits:
-
AppDiagram
- Object
- AppDiagram
- ControllersDiagram
- Defined in:
- lib/prailroady/controllers_diagram.rb
Overview
PrailRoady 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
- #engine_files ⇒ Object
- #extract_class_name(filename) ⇒ Object
-
#generate ⇒ Object
Process controller files.
- #get_files(prefix = '') ⇒ Object
-
#initialize(options = OptionsStruct.new) ⇒ ControllersDiagram
constructor
A new instance of ControllersDiagram.
Methods inherited from AppDiagram
Constructor Details
#initialize(options = OptionsStruct.new) ⇒ ControllersDiagram
Returns a new instance of ControllersDiagram.
15 16 17 18 19 |
# File 'lib/prailroady/controllers_diagram.rb', line 15 def initialize( = OptionsStruct.new) # options.exclude.map! {|e| "app/controllers/" + e} super @graph.diagram_type = 'Controllers' end |
Instance Method Details
#engine_files ⇒ Object
46 47 48 |
# File 'lib/prailroady/controllers_diagram.rb', line 46 def engine_files engines.collect { |engine| Dir.glob("#{engine.root}/app/controllers/**/*_controller.rb") }.flatten end |
#extract_class_name(filename) ⇒ Object
50 51 52 |
# File 'lib/prailroady/controllers_diagram.rb', line 50 def extract_class_name(filename) filename.match(%r{.*/controllers/(.*).rb$})[1].camelize end |
#generate ⇒ Object
Process controller files
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prailroady/controllers_diagram.rb', line 22 def generate $stderr.print "Generating controllers diagram\n" if .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 #{$ERROR_INFO} raised while trying to load controller class #{f}" end end end |
#get_files(prefix = '') ⇒ Object
39 40 41 42 43 44 |
# File 'lib/prailroady/controllers_diagram.rb', line 39 def get_files(prefix = '') files = !.specify.empty? ? Dir.glob(.specify) : Dir.glob(prefix << 'app/controllers/**/*_controller.rb') files += engine_files if .engine_controllers files -= Dir.glob(.exclude) files end |