@@ -39,7 +39,7 @@ module AnnotateModels
3939 }
4040 } . freeze
4141
42- MAGIC_COMMENT_MATCHER = Regexp . new ( /(^#\s *encoding:.*(?:\n |r\n ))|(^# coding:.*(?:\n |\r \n ))|(^# -\* - coding:.*(?:\n |\r \n ))|(^# -\* - encoding\s ?:.*(?:\n |\r \n ))|(^#\s *frozen_string_literal:.+(?:\n |\r \n ))|(^# -\* - frozen_string_literal\s *:.+-\* -(?:\n |\r \n ))/ ) . freeze
42+ MAGIC_COMMENT_MATCHER = /(^#\s *encoding:.*(?:\n |r\n ))|(^# coding:.*(?:\n |\r \n ))|(^# -\* - coding:.*(?:\n |\r \n ))|(^# -\* - encoding\s ?:.*(?:\n |\r \n ))|(^#\s *frozen_string_literal:.+(?:\n |\r \n ))|(^# -\* - frozen_string_literal\s *:.+-\* -(?:\n |\r \n ))/
4343
4444 class << self
4545 def annotate_pattern ( options = { } )
@@ -155,8 +155,8 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
155155 with_comments_column = with_comments_column? ( klass , options )
156156
157157 # Precalculate Values
158- cols_meta = cols . map do |col |
159- col_comment = with_comments || with_comments_column ? col . comment &.gsub ( / \n / , "\\ n" ) : nil
158+ cols_meta = cols . to_h do |col |
159+ col_comment = with_comments || with_comments_column ? col . comment &.gsub ( " \n " , "\\ n" ) : nil
160160 col_type = get_col_type ( col )
161161 attrs = get_attributes ( col , col_type , klass , options )
162162 col_name = if with_comments && col_comment
@@ -166,7 +166,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
166166 end
167167 simple_formatted_attrs = attrs . join ( ", " )
168168 [ col . name , { col_type : col_type , attrs : attrs , col_name : col_name , simple_formatted_attrs : simple_formatted_attrs , col_comment : col_comment } ]
169- end . to_h
169+ end
170170
171171 # Output annotation
172172 bare_max_attrs_length = cols_meta . map { |_ , m | m [ :simple_formatted_attrs ] . length } . max
@@ -179,15 +179,15 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
179179 col_comment = cols_meta [ col . name ] [ :col_comment ]
180180
181181 if options [ :format_rdoc ]
182- info << sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + "\n "
182+ info << ( sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + "\n " )
183183 elsif options [ :format_yard ]
184- info << sprintf ( "# @!attribute #{ col_name } " ) + "\n "
184+ info << ( "# @!attribute #{ col_name } " + "\n " )
185185 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 )
186- info << sprintf ( "# @return [#{ ruby_class } ]" ) + "\n "
186+ info << ( "# @return [#{ ruby_class } ]" + "\n " )
187187 elsif options [ :format_markdown ]
188188 name_remainder = max_size - col_name . length - non_ascii_length ( col_name )
189189 type_remainder = ( md_type_allowance - 2 ) - col_type . length
190- info << ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col_name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub ( '``' , ' ' ) . rstrip + "\n "
190+ info << ( ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col_name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub ( '``' , ' ' ) . rstrip + "\n " )
191191 elsif with_comments_column
192192 info << format_default ( col_name , max_size , col_type , bare_type_allowance , simple_formatted_attrs , bare_max_attrs_length , col_comment )
193193 else
@@ -423,7 +423,7 @@ def get_check_constraint_info(klass, options = {})
423423 # :position_in_*<Symbol>:: where to place the annotated section in fixture or model file,
424424 # :before, :top, :after or :bottom. Default is :before.
425425 #
426- def annotate_one_file ( file_name , info_block , position , options = { } )
426+ def annotate_one_file? ( file_name , info_block , position , options = { } )
427427 return false unless File . exist? ( file_name )
428428 old_content = File . read ( file_name )
429429 return false if old_content =~ /#{ SKIP_ANNOTATION_PREFIX } .*\n /
@@ -486,7 +486,7 @@ def magic_comments_as_string(content)
486486 end
487487 end
488488
489- def remove_annotation_of_file ( file_name , options = { } )
489+ def remove_annotation_of_file? ( file_name , options = { } )
490490 if File . exist? ( file_name )
491491 content = File . read ( file_name )
492492 return false if content =~ /#{ SKIP_ANNOTATION_PREFIX } .*\n /
@@ -542,7 +542,7 @@ def annotate(klass, file, header, options = {})
542542 model_file_name = File . join ( file )
543543 annotated = [ ]
544544
545- if annotate_one_file ( model_file_name , info , :position_in_class , options_with_position ( options , :position_in_class ) )
545+ if annotate_one_file? ( model_file_name , info , :position_in_class , options_with_position ( options , :position_in_class ) )
546546 annotated << model_file_name
547547 end
548548
@@ -563,7 +563,7 @@ def annotate(klass, file, header, options = {})
563563 . map { |f | expand_glob_into_files ( f ) }
564564 . flatten
565565 . each do |f |
566- if annotate_one_file ( f , info , position_key , options_with_position ( options , position_key ) )
566+ if annotate_one_file? ( f , info , position_key , options_with_position ( options , position_key ) )
567567 annotated << f
568568 end
569569 end
@@ -694,7 +694,7 @@ def parse_options(options = {})
694694 end
695695
696696 def split_model_dir ( option_value )
697- option_value = option_value . is_a? ( Array ) ? option_value : option_value . split ( ',' )
697+ option_value = option_value . split ( ',' ) unless option_value . is_a? ( Array )
698698 option_value . map ( &:strip ) . reject ( &:empty? )
699699 end
700700
@@ -762,13 +762,13 @@ def remove_annotations(options = {})
762762 model_name = klass . name . underscore
763763 table_name = klass . table_name
764764 model_file_name = file
765- deannotated_klass = true if remove_annotation_of_file ( model_file_name , options )
765+ deannotated_klass = true if remove_annotation_of_file? ( model_file_name , options )
766766
767767 get_patterns ( options , matched_types ( options ) )
768768 . map { |f | resolve_filename ( f , model_name , table_name ) }
769769 . each do |f |
770770 if File . exist? ( f )
771- remove_annotation_of_file ( f , options )
771+ remove_annotation_of_file? ( f , options )
772772 deannotated_klass = true
773773 end
774774 end
0 commit comments