Class: ModelsDiagram
- Inherits:
-
AppDiagram
- Object
- AppDiagram
- ModelsDiagram
- Defined in:
- lib/railroad/models_diagram.rb
Overview
RailRoad models diagram
Instance Method Summary collapse
-
#generate ⇒ Object
Process model files.
-
#initialize(options) ⇒ ModelsDiagram
constructor
A new instance of ModelsDiagram.
Methods inherited from AppDiagram
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.exclude.map! {|e| "app/models/" + e} super @graph.diagram_type = 'Models' # Processed habtm associations @habtm = [] end |
Instance Method Details
#generate ⇒ Object
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/railroad/models_diagram.rb', line 19 def generate STDERR.print "Generating models diagram\n" if @options.verbose base = "(app/models/|lib/)" files = Dir.glob("app/models/**/*.rb") files += Dir.glob("vendor/plugins/**/app/models/*.rb") if @options.plugins_models files += Dir.glob("lib/**/*.rb") if @options.libraries files -= @options.exclude (files + ['filter_condition_type']).each do |file| model_name = @options.classes_by_files[file] || (model_path = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\2')).camelize STDERR.print "Processing #{file} ...\n" if @options.verbose # Hack to skip all xxx_related.rb files next if /_related/i =~ model_name klass = begin model_name.constantize rescue LoadError STDERR.print "\t#{model_name} raised LoadError.\n" if @options.verbose oldlen = model_path.length model_path.gsub!(/.*[\/\\]/, '') model_name = model_path.camelize if oldlen > model_path.length retry end STDERR.print "\tDone trying to remove slashes, skipping this model.\n" if @options.verbose next rescue NameError STDERR.print "\t#{model_name} raised NameError, skipping this model.\n" if @options.verbose next end process_class klass STDERR.print "Done #{file}\n" if @options.verbose end end |