Class: ModelsDiagram

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

Overview

RailRoad models diagram

Instance Method Summary collapse

Methods inherited from AppDiagram

#print

Constructor Details

#initialize(options) ⇒ ModelsDiagram

Returns a new instance of ModelsDiagram.



10
11
12
13
14
15
16
# File 'lib/railroad/models_diagram.rb', line 10

def initialize(options)
  #options.exclude.map! {|e| "app/models/" + e}
  super options 
  @graph.diagram_type = 'Models'
  # Processed habtm associations
  @habtm = []
end

Instance Method Details

#generateObject

Process model files



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/railroad/models_diagram.rb', line 19

def generate
  STDERR.print "Generating models diagram\n" if @options.verbose
  base = "app/models/"
  files = Dir.glob("app/models/**/*.rb")
  files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models    
  files -= @options.exclude
  files.each do |file| 
    model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1')      
    # Hack to skip all xxx_related.rb files
    next if /_related/i =~ model_name

    klass = begin
      model_name.classify.constantize
    rescue LoadError
      model_name.gsub!(/.*[\/\\]/, '')
      retry
    rescue NameError
      next
    end

    process_class klass
  end
end