@@ -320,7 +320,9 @@ def get_foreign_key_info(klass, options={})
320320 # a schema info block (a comment starting with "== Schema Information"), check if it
321321 # matches the block that is already there. If so, leave it be. If not, remove the old
322322 # info block and write a new one.
323- # Returns true or false depending on whether the file was modified.
323+ #
324+ # == Returns:
325+ # true or false depending on whether the file was modified.
324326 #
325327 # === Options (opts)
326328 # :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
@@ -394,8 +396,6 @@ def remove_annotation_of_file(file_name)
394396 # info block (basically a comment containing information
395397 # on the columns and their types) and put it at the front
396398 # of the model and fixture source files.
397- # Returns true or false depending on whether the source
398- # files were modified.
399399 #
400400 # === Options (opts)
401401 # :position_in_class<Symbol>:: where to place the annotated section in model file
@@ -411,35 +411,41 @@ def remove_annotation_of_file(file_name)
411411 # :exclude_controllers<Symbol>:: whether to skip modification of controller files
412412 # :exclude_helpers<Symbol>:: whether to skip modification of helper files
413413 #
414+ # == Returns:
415+ # an array of file names that were annotated.
416+ #
414417 def annotate ( klass , file , header , options = { } )
415418 begin
416419 info = get_schema_info ( klass , header , options )
417- did_annotate = false
418420 model_name = klass . name . underscore
419421 table_name = klass . table_name
420422 model_file_name = File . join ( file )
423+ annotated = [ ]
421424
422425 if annotate_one_file ( model_file_name , info , :position_in_class , options_with_position ( options , :position_in_class ) )
423- did_annotate = true
426+ annotated << model_file_name
424427 end
425428
426429 MATCHED_TYPES . each do |key |
427430 exclusion_key = "exclude_#{ key . pluralize } " . to_sym
428431 position_key = "position_in_#{ key } " . to_sym
429432
430433 unless options [ exclusion_key ]
431- did_annotate = self . get_patterns ( key ) .
434+ self . get_patterns ( key ) .
432435 map { |f | resolve_filename ( f , model_name , table_name ) } .
433- map { |f | annotate_one_file ( f , info , position_key , options_with_position ( options , position_key ) ) } .
434- detect { |result | result } || did_annotate
436+ each { |f |
437+ if annotate_one_file ( f , info , position_key , options_with_position ( options , position_key ) )
438+ annotated << f
439+ end
440+ }
435441 end
436442 end
437-
438- return did_annotate
439443 rescue Exception => e
440444 puts "Unable to annotate #{ file } : #{ e . message } "
441445 puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
442446 end
447+
448+ return annotated
443449 end
444450
445451 # position = :position_in_fixture or :position_in_class
@@ -537,9 +543,10 @@ def do_annotations(options={})
537543 self . root_dir = options [ :root_dir ] if options [ :root_dir ]
538544
539545 annotated = [ ]
540- get_model_files ( options ) . each do |file |
541- annotate_model_file ( annotated , File . join ( file ) , header , options )
546+ get_model_files ( options ) . each do |path , filename |
547+ annotate_model_file ( annotated , File . join ( path , filename ) , header , options )
542548 end
549+
543550 if annotated . empty?
544551 puts "Model files unchanged."
545552 else
@@ -552,9 +559,7 @@ def annotate_model_file(annotated, file, header, options)
552559 return false if ( /# -\* - SkipSchemaAnnotations.*/ =~ ( File . exist? ( file ) ? File . read ( file ) : '' ) )
553560 klass = get_model_class ( file )
554561 if klass && klass < ActiveRecord ::Base && !klass . abstract_class? && klass . table_exists?
555- if annotate ( klass , file , header , options )
556- annotated << file
557- end
562+ annotated . concat ( annotate ( klass , file , header , options ) )
558563 end
559564 rescue BadModelFileError => e
560565 unless options [ :ignore_unknown_models ]
0 commit comments