@@ -53,7 +53,7 @@ def model_dir
53
53
@model_dir . is_a? ( Array ) ? @model_dir : [ @model_dir || 'app/models' ]
54
54
end
55
55
56
- attr_writer :model_dir
56
+ attr_writer :model_dir , :root_dir , :skip_subdirectory_model_load
57
57
58
58
def root_dir
59
59
if @root_dir . blank?
@@ -65,8 +65,6 @@ def root_dir
65
65
end
66
66
end
67
67
68
- attr_writer :root_dir
69
-
70
68
def skip_subdirectory_model_load
71
69
# This option is set in options[:skip_subdirectory_model_load]
72
70
# and stops the get_loaded_model method from loading a model from a subdir
@@ -78,8 +76,6 @@ def skip_subdirectory_model_load
78
76
end
79
77
end
80
78
81
- attr_writer :skip_subdirectory_model_load
82
-
83
79
def get_patterns ( options , pattern_types = [ ] )
84
80
current_patterns = [ ]
85
81
root_dir . each do |root_directory |
@@ -89,7 +85,7 @@ def get_patterns(options, pattern_types = [])
89
85
current_patterns += if pattern_type . to_sym == :additional_file_patterns
90
86
patterns
91
87
else
92
- patterns . map { |p | p . sub ( /^[ \/ ] */ , '' ) }
88
+ patterns . map { |p | p . sub ( /^\/ */ , '' ) }
93
89
end
94
90
end
95
91
end
@@ -156,15 +152,15 @@ def get_schema_info(klass, header, options = {})
156
152
end
157
153
158
154
if options [ :format_rdoc ]
159
- info << sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + " \n "
155
+ info << " #{ sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip } \n "
160
156
elsif options [ :format_yard ]
161
- info << sprintf ( "# @!attribute #{ col_name } " ) + " \n "
157
+ info << " #{ sprintf ( "# @!attribute #{ col_name } " ) } \n "
162
158
ruby_class = col . respond_to? ( :array ) && col . array ? "Array<#{ map_col_type_to_ruby_classes ( col_type ) } >" : map_col_type_to_ruby_classes ( col_type )
163
- info << sprintf ( "# @return [#{ ruby_class } ]" ) + " \n "
159
+ info << " #{ sprintf ( "# @return [#{ ruby_class } ]" ) } \n "
164
160
elsif options [ :format_markdown ]
165
161
name_remainder = max_size - col_name . length - non_ascii_length ( col_name )
166
162
type_remainder = ( md_type_allowance - 2 ) - col_type . length
167
- info << ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col_name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub ( '``' , ' ' ) . rstrip + " \n "
163
+ info << " #{ ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col_name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub ( '``' , ' ' ) . rstrip } \n "
168
164
else
169
165
info << format_default ( col_name , max_size , col_type , bare_type_allowance , attrs )
170
166
end
@@ -345,7 +341,7 @@ def get_foreign_key_info(klass, options = {})
345
341
fk_info << if options [ :format_markdown ]
346
342
sprintf ( "# * `%s`%s:\n # * **`%s`**\n " , format_name . call ( fk ) , constraints_info . blank? ? '' : " (_#{ constraints_info } _)" , ref_info )
347
343
else
348
- sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , format_name . call ( fk ) , "(#{ ref_info } )" , constraints_info ) . rstrip + " \n "
344
+ " #{ sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , format_name . call ( fk ) , "(#{ ref_info } )" , constraints_info ) . rstrip } \n "
349
345
end
350
346
end
351
347
@@ -371,11 +367,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
371
367
return false if old_content =~ /#{ SKIP_ANNOTATION_PREFIX } .*\n /
372
368
373
369
# Ignore the Schema version line because it changes with each migration
374
- header_pattern = /(^# Table name:.*?\n (#.*[ \r ] ?\n )*[ \r ] ?)/
370
+ header_pattern = /(^# Table name:.*?\n (#.*\r ?\n )*\r ?)/
375
371
old_header = old_content . match ( header_pattern ) . to_s
376
372
new_header = info_block . match ( header_pattern ) . to_s
377
373
378
- column_pattern = /^#[\t ]+[\w \* \ . `]+[\t ]+.+$/
374
+ column_pattern = /^#[\t ]+[\w * .`]+[\t ]+.+$/
379
375
old_columns = old_header && old_header . scan ( column_pattern ) . sort
380
376
new_columns = new_header && new_header . scan ( column_pattern ) . sort
381
377
@@ -398,11 +394,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
398
394
old_content . sub! ( annotate_pattern ( options ) , '' )
399
395
400
396
new_content = if %w( after bottom ) . include? ( options [ position ] . to_s )
401
- magic_comments_block + ( old_content . rstrip + " \n \n " + wrapped_info_block )
397
+ magic_comments_block + ( " #{ old_content . rstrip } \n \n #{ wrapped_info_block } " )
402
398
elsif magic_comments_block . empty?
403
399
magic_comments_block + wrapped_info_block + old_content . lstrip
404
400
else
405
- magic_comments_block + " \n " + wrapped_info_block + old_content . lstrip
401
+ " #{ magic_comments_block } \n #{ wrapped_info_block } #{ old_content . lstrip } "
406
402
end
407
403
else
408
404
# replace the old annotation with the new one
@@ -512,7 +508,7 @@ def annotate(klass, file, header, options = {})
512
508
end
513
509
rescue StandardError => e
514
510
$stderr. puts "Unable to annotate #{ file } : #{ e . message } "
515
- $stderr. puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
511
+ $stderr. puts "\t #{ e . backtrace . join ( "\n \t " ) } " if options [ :trace ]
516
512
end
517
513
518
514
annotated
@@ -589,7 +585,7 @@ def get_model_class(file)
589
585
if File . file? ( file_path ) && Kernel . require ( file_path )
590
586
retry
591
587
elsif model_path =~ /\/ /
592
- model_path = model_path . split ( '/' ) [ 1 ..- 1 ] . join ( '/' ) . to_s
588
+ model_path = model_path . split ( '/' ) [ 1 ..] . join ( '/' ) . to_s
593
589
retry
594
590
else
595
591
raise
@@ -625,7 +621,7 @@ def get_loaded_model_by_path(model_path)
625
621
# Revert to the old way but it is not really robust
626
622
ObjectSpace . each_object ( ::Class )
627
623
. select do |c |
628
- Class === c && # note : we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
624
+ Class === c && # NOTE : we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
629
625
c . ancestors . respond_to? ( :include? ) && # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
630
626
c . ancestors . include? ( ActiveRecord ::Base )
631
627
end . detect { |c | ActiveSupport ::Inflector . underscore ( c . to_s ) == model_path }
@@ -685,11 +681,11 @@ def annotate_model_file(annotated, file, header, options)
685
681
rescue BadModelFileError => e
686
682
unless options [ :ignore_unknown_models ]
687
683
$stderr. puts "Unable to annotate #{ file } : #{ e . message } "
688
- $stderr. puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
684
+ $stderr. puts "\t #{ e . backtrace . join ( "\n \t " ) } " if options [ :trace ]
689
685
end
690
686
rescue StandardError => e
691
687
$stderr. puts "Unable to annotate #{ file } : #{ e . message } "
692
- $stderr. puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
688
+ $stderr. puts "\t #{ e . backtrace . join ( "\n \t " ) } " if options [ :trace ]
693
689
end
694
690
end
695
691
@@ -720,7 +716,7 @@ def remove_annotations(options = {})
720
716
deannotated << klass if deannotated_klass
721
717
rescue StandardError => e
722
718
$stderr. puts "Unable to deannotate #{ File . join ( file ) } : #{ e . message } "
723
- $stderr. puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
719
+ $stderr. puts "\t #{ e . backtrace . join ( "\n \t " ) } " if options [ :trace ]
724
720
end
725
721
end
726
722
puts "Removed annotations from: #{ deannotated . join ( ', ' ) } "
@@ -780,7 +776,7 @@ def max_schema_info_width(klass, options)
780
776
end
781
777
782
778
def format_default ( col_name , max_size , col_type , bare_type_allowance , attrs )
783
- sprintf ( "# %s:%s %s" , mb_chars_ljust ( col_name , max_size ) , mb_chars_ljust ( col_type , bare_type_allowance ) , attrs . join ( ", " ) ) . rstrip + " \n "
779
+ " #{ sprintf ( "# %s:%s %s" , mb_chars_ljust ( col_name , max_size ) , mb_chars_ljust ( col_type , bare_type_allowance ) , attrs . join ( ", " ) ) . rstrip } \n "
784
780
end
785
781
786
782
def width ( string )
0 commit comments