@@ -39,7 +39,15 @@ module AnnotateModels
39
39
}
40
40
} . freeze
41
41
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 = Regexp . new (
43
+ '(^#\s*encoding:.*(?:\n|\r\n))' \
44
+ + '|(^# coding:.*(?:\n|\r\n))' \
45
+ + '|(^# -\*- coding:.*(?:\n|\r\n))' \
46
+ + '|(^# -\*- encoding\s?:.*(?:\n|\r\n))' \
47
+ + '|(^#\s*frozen_string_literal:.+(?:\n|\r\n))' \
48
+ + '|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))' \
49
+ + '|(^#\s*typed:.+(?:\n|\r\n))'
50
+ ) . freeze
43
51
44
52
class << self
45
53
def annotate_pattern ( options = { } )
@@ -145,7 +153,9 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
145
153
bare_type_allowance = 16
146
154
147
155
if options [ :format_markdown ]
148
- info << sprintf ( "# %-#{ max_size + md_names_overhead } .#{ max_size + md_names_overhead } s | %-#{ md_type_allowance } .#{ md_type_allowance } s | %s\n " , 'Name' , 'Type' , 'Attributes' )
156
+ info << sprintf (
157
+ "# %-#{ max_size + md_names_overhead } .#{ max_size + md_names_overhead } s | %-#{ md_type_allowance } .#{ md_type_allowance } s | %s\n " , 'Name' , 'Type' , 'Attributes'
158
+ )
149
159
150
160
info << "# #{ '-' * ( max_size + md_names_overhead ) } | #{ '-' * md_type_allowance } | #{ '-' * 27 } \n "
151
161
end
@@ -165,7 +175,9 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
165
175
col . name
166
176
end
167
177
simple_formatted_attrs = attrs . join ( ", " )
168
- [ col . name , { col_type : col_type , attrs : attrs , col_name : col_name , simple_formatted_attrs : simple_formatted_attrs , col_comment : col_comment } ]
178
+ [ col . name ,
179
+ { col_type : col_type , attrs : attrs , col_name : col_name , simple_formatted_attrs : simple_formatted_attrs ,
180
+ col_comment : col_comment } ]
169
181
end . to_h
170
182
171
183
# Output annotation
@@ -179,17 +191,21 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
179
191
col_comment = cols_meta [ col . name ] [ :col_comment ]
180
192
181
193
if options [ :format_rdoc ]
182
- info << sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" , attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + "\n "
194
+ info << sprintf ( "# %-#{ max_size } .#{ max_size } s<tt>%s</tt>" , "*#{ col_name } *::" ,
195
+ attrs . unshift ( col_type ) . join ( ", " ) ) . rstrip + "\n "
183
196
elsif options [ :format_yard ]
184
197
info << sprintf ( "# @!attribute #{ col_name } " ) + "\n "
185
198
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
199
info << sprintf ( "# @return [#{ ruby_class } ]" ) + "\n "
187
200
elsif options [ :format_markdown ]
188
201
name_remainder = max_size - col_name . length - non_ascii_length ( col_name )
189
202
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 "
203
+ info << ( sprintf ( "# **`%s`**%#{ name_remainder } s | `%s`%#{ type_remainder } s | `%s`" , col_name , " " , col_type , " " , attrs . join ( ", " ) . rstrip ) ) . gsub (
204
+ '``' , ' '
205
+ ) . rstrip + "\n "
191
206
elsif with_comments_column
192
- info << format_default ( col_name , max_size , col_type , bare_type_allowance , simple_formatted_attrs , bare_max_attrs_length , col_comment )
207
+ info << format_default ( col_name , max_size , col_type , bare_type_allowance , simple_formatted_attrs ,
208
+ bare_max_attrs_length , col_comment )
193
209
else
194
210
info << format_default ( col_name , max_size , col_type , bare_type_allowance , simple_formatted_attrs )
195
211
end
@@ -372,9 +388,11 @@ def get_foreign_key_info(klass, options = {})
372
388
constraints_info . strip!
373
389
374
390
fk_info << if options [ :format_markdown ]
375
- sprintf ( "# * `%s`%s:\n # * **`%s`**\n " , format_name . call ( fk ) , constraints_info . blank? ? '' : " (_#{ constraints_info } _)" , ref_info )
391
+ sprintf ( "# * `%s`%s:\n # * **`%s`**\n " , format_name . call ( fk ) ,
392
+ constraints_info . blank? ? '' : " (_#{ constraints_info } _)" , ref_info )
376
393
else
377
- sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , format_name . call ( fk ) , "(#{ ref_info } )" , constraints_info ) . rstrip + "\n "
394
+ sprintf ( "# %-#{ max_size } .#{ max_size } s %s %s" , format_name . call ( fk ) , "(#{ ref_info } )" ,
395
+ constraints_info ) . rstrip + "\n "
378
396
end
379
397
end
380
398
@@ -542,7 +560,8 @@ def annotate(klass, file, header, options = {})
542
560
model_file_name = File . join ( file )
543
561
annotated = [ ]
544
562
545
- if annotate_one_file ( model_file_name , info , :position_in_class , options_with_position ( options , :position_in_class ) )
563
+ if annotate_one_file ( model_file_name , info , :position_in_class ,
564
+ options_with_position ( options , :position_in_class ) )
546
565
annotated << model_file_name
547
566
end
548
567
@@ -935,7 +954,8 @@ def ignored_translation_table_colums(klass)
935
954
# a given column.
936
955
def get_attributes ( column , column_type , klass , options )
937
956
attrs = [ ]
938
- attrs << "default(#{ schema_default ( klass , column ) } )" unless column . default . nil? || hide_default? ( column_type , options )
957
+ attrs << "default(#{ schema_default ( klass , column ) } )" unless column . default . nil? || hide_default? ( column_type ,
958
+ options )
939
959
attrs << 'unsigned' if column . respond_to? ( :unsigned? ) && column . unsigned?
940
960
attrs << 'not null' unless column . null
941
961
attrs << 'primary key' if klass . primary_key && ( klass . primary_key . is_a? ( Array ) ? klass . primary_key . collect ( &:to_sym ) . include? ( column . name . to_sym ) : column . name . to_sym == klass . primary_key . to_sym )
0 commit comments