@@ -320,7 +320,9 @@ def get_foreign_key_info(klass, options={})
320
320
# a schema info block (a comment starting with "== Schema Information"), check if it
321
321
# matches the block that is already there. If so, leave it be. If not, remove the old
322
322
# 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.
324
326
#
325
327
# === Options (opts)
326
328
# :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)
394
396
# info block (basically a comment containing information
395
397
# on the columns and their types) and put it at the front
396
398
# of the model and fixture source files.
397
- # Returns true or false depending on whether the source
398
- # files were modified.
399
399
#
400
400
# === Options (opts)
401
401
# :position_in_class<Symbol>:: where to place the annotated section in model file
@@ -411,35 +411,41 @@ def remove_annotation_of_file(file_name)
411
411
# :exclude_controllers<Symbol>:: whether to skip modification of controller files
412
412
# :exclude_helpers<Symbol>:: whether to skip modification of helper files
413
413
#
414
+ # == Returns:
415
+ # an array of file names that were annotated.
416
+ #
414
417
def annotate ( klass , file , header , options = { } )
415
418
begin
416
419
info = get_schema_info ( klass , header , options )
417
- did_annotate = false
418
420
model_name = klass . name . underscore
419
421
table_name = klass . table_name
420
422
model_file_name = File . join ( file )
423
+ annotated = [ ]
421
424
422
425
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
424
427
end
425
428
426
429
MATCHED_TYPES . each do |key |
427
430
exclusion_key = "exclude_#{ key . pluralize } " . to_sym
428
431
position_key = "position_in_#{ key } " . to_sym
429
432
430
433
unless options [ exclusion_key ]
431
- did_annotate = self . get_patterns ( key ) .
434
+ self . get_patterns ( key ) .
432
435
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
+ }
435
441
end
436
442
end
437
-
438
- return did_annotate
439
443
rescue Exception => e
440
444
puts "Unable to annotate #{ file } : #{ e . message } "
441
445
puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
442
446
end
447
+
448
+ return annotated
443
449
end
444
450
445
451
# position = :position_in_fixture or :position_in_class
@@ -537,9 +543,10 @@ def do_annotations(options={})
537
543
self . root_dir = options [ :root_dir ] if options [ :root_dir ]
538
544
539
545
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 )
542
548
end
549
+
543
550
if annotated . empty?
544
551
puts "Model files unchanged."
545
552
else
@@ -552,9 +559,7 @@ def annotate_model_file(annotated, file, header, options)
552
559
return false if ( /# -\* - SkipSchemaAnnotations.*/ =~ ( File . exist? ( file ) ? File . read ( file ) : '' ) )
553
560
klass = get_model_class ( file )
554
561
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 ) )
558
563
end
559
564
rescue BadModelFileError => e
560
565
unless options [ :ignore_unknown_models ]
0 commit comments