@@ -53,7 +53,7 @@ def model_dir
5353 @model_dir . is_a? ( Array ) ? @model_dir : [ @model_dir || 'app/models' ]
5454 end
5555
56- attr_writer :model_dir
56+ attr_writer :model_dir , :root_dir , :skip_subdirectory_model_load
5757
5858 def root_dir
5959 if @root_dir . blank?
@@ -65,8 +65,6 @@ def root_dir
6565 end
6666 end
6767
68- attr_writer :root_dir
69-
7068 def skip_subdirectory_model_load
7169 # This option is set in options[:skip_subdirectory_model_load]
7270 # and stops the get_loaded_model method from loading a model from a subdir
@@ -78,8 +76,6 @@ def skip_subdirectory_model_load
7876 end
7977 end
8078
81- attr_writer :skip_subdirectory_model_load
82-
8379 def get_patterns ( options , pattern_types = [ ] )
8480 current_patterns = [ ]
8581 root_dir . each do |root_directory |
@@ -89,7 +85,7 @@ def get_patterns(options, pattern_types = [])
8985 current_patterns += if pattern_type . to_sym == :additional_file_patterns
9086 patterns
9187 else
92- patterns . map { |p | p . sub ( /^[ \/ ] */ , '' ) }
88+ patterns . map { |p | p . sub ( /^\/ */ , '' ) }
9389 end
9490 end
9591 end
@@ -156,15 +152,15 @@ def get_schema_info(klass, header, options = {})
156152 end
157153
158154 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 "
160156 elsif options [ :format_yard ]
161- info << sprintf ( "# @!attribute #{ col_name } " ) + " \n "
157+ info << " #{ sprintf ( "# @!attribute #{ col_name } " ) } \n "
162158 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 "
164160 elsif options [ :format_markdown ]
165161 name_remainder = max_size - col_name . length - non_ascii_length ( col_name )
166162 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 "
168164 else
169165 info << format_default ( col_name , max_size , col_type , bare_type_allowance , attrs )
170166 end
@@ -345,7 +341,7 @@ def get_foreign_key_info(klass, options = {})
345341 fk_info << if options [ :format_markdown ]
346342 sprintf ( "# * `%s`%s:\n # * **`%s`**\n " , format_name . call ( fk ) , constraints_info . blank? ? '' : " (_#{ constraints_info } _)" , ref_info )
347343 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 "
349345 end
350346 end
351347
@@ -371,11 +367,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
371367 return false if old_content =~ /#{ SKIP_ANNOTATION_PREFIX } .*\n /
372368
373369 # 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 ?)/
375371 old_header = old_content . match ( header_pattern ) . to_s
376372 new_header = info_block . match ( header_pattern ) . to_s
377373
378- column_pattern = /^#[\t ]+[\w \* \ . `]+[\t ]+.+$/
374+ column_pattern = /^#[\t ]+[\w * .`]+[\t ]+.+$/
379375 old_columns = old_header && old_header . scan ( column_pattern ) . sort
380376 new_columns = new_header && new_header . scan ( column_pattern ) . sort
381377
@@ -398,11 +394,11 @@ def annotate_one_file(file_name, info_block, position, options = {})
398394 old_content . sub! ( annotate_pattern ( options ) , '' )
399395
400396 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 } " )
402398 elsif magic_comments_block . empty?
403399 magic_comments_block + wrapped_info_block + old_content . lstrip
404400 else
405- magic_comments_block + " \n " + wrapped_info_block + old_content . lstrip
401+ " #{ magic_comments_block } \n #{ wrapped_info_block } #{ old_content . lstrip } "
406402 end
407403 else
408404 # replace the old annotation with the new one
@@ -512,7 +508,7 @@ def annotate(klass, file, header, options = {})
512508 end
513509 rescue StandardError => e
514510 $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 ]
516512 end
517513
518514 annotated
@@ -589,7 +585,7 @@ def get_model_class(file)
589585 if File . file? ( file_path ) && Kernel . require ( file_path )
590586 retry
591587 elsif model_path =~ /\/ /
592- model_path = model_path . split ( '/' ) [ 1 ..- 1 ] . join ( '/' ) . to_s
588+ model_path = model_path . split ( '/' ) [ 1 ..] . join ( '/' ) . to_s
593589 retry
594590 else
595591 raise
@@ -625,7 +621,7 @@ def get_loaded_model_by_path(model_path)
625621 # Revert to the old way but it is not really robust
626622 ObjectSpace . each_object ( ::Class )
627623 . 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?
629625 c . ancestors . respond_to? ( :include? ) && # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
630626 c . ancestors . include? ( ActiveRecord ::Base )
631627 end . detect { |c | ActiveSupport ::Inflector . underscore ( c . to_s ) == model_path }
@@ -685,11 +681,11 @@ def annotate_model_file(annotated, file, header, options)
685681 rescue BadModelFileError => e
686682 unless options [ :ignore_unknown_models ]
687683 $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 ]
689685 end
690686 rescue StandardError => e
691687 $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 ]
693689 end
694690 end
695691
@@ -720,7 +716,7 @@ def remove_annotations(options = {})
720716 deannotated << klass if deannotated_klass
721717 rescue StandardError => e
722718 $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 ]
724720 end
725721 end
726722 puts "Removed annotations from: #{ deannotated . join ( ', ' ) } "
@@ -780,7 +776,7 @@ def max_schema_info_width(klass, options)
780776 end
781777
782778 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 "
784780 end
785781
786782 def width ( string )
0 commit comments