Method: AnnotateModels.annotate_model_file

Defined in:
lib/annotate/annotate_models.rb

.annotate_model_file(annotated, file, header, options) ⇒ Object



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/annotate/annotate_models.rb', line 672

def annotate_model_file(annotated, file, header, options)
  begin
    return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '')
    klass = get_model_class(file)
    do_annotate = klass.is_a?(Class) &&
      klass < ActiveRecord::Base &&
      (!options[:exclude_sti_subclasses] || !(klass.superclass < ActiveRecord::Base && klass.table_name == klass.superclass.table_name)) &&
      !klass.abstract_class? &&
      klass.table_exists?

    annotated.concat(annotate(klass, file, header, options)) if do_annotate
  rescue BadModelFileError => e
    unless options[:ignore_unknown_models]
      $stderr.puts "Unable to annotate #{file}: #{e.message}"
      $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
    end
  rescue StandardError => e
    $stderr.puts "Unable to annotate #{file}: #{e.message}"
    $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
  end
end