@@ -249,49 +249,7 @@ def get_schema_info(klass, header, options = {})
249
249
cols = columns ( klass , options )
250
250
cols . each do |col |
251
251
col_type = get_col_type ( col )
252
- attrs = [ ]
253
- attrs << "default(#{ schema_default ( klass , col ) } )" unless col . default . nil? || hide_default? ( col_type , options )
254
- attrs << 'unsigned' if col . respond_to? ( :unsigned? ) && col . unsigned?
255
- attrs << 'not null' unless col . null
256
- attrs << 'primary key' if klass . primary_key && ( klass . primary_key . is_a? ( Array ) ? klass . primary_key . collect ( &:to_sym ) . include? ( col . name . to_sym ) : col . name . to_sym == klass . primary_key . to_sym )
257
-
258
- if col_type == 'decimal'
259
- col_type << "(#{ col . precision } , #{ col . scale } )"
260
- elsif !%w[ spatial geometry geography ] . include? ( col_type )
261
- if col . limit && !options [ :format_yard ]
262
- if col . limit . is_a? Array
263
- attrs << "(#{ col . limit . join ( ', ' ) } )"
264
- else
265
- col_type << "(#{ col . limit } )" unless hide_limit? ( col_type , options )
266
- end
267
- end
268
- end
269
-
270
- # Check out if we got an array column
271
- attrs << 'is an Array' if col . respond_to? ( :array ) && col . array
272
-
273
- # Check out if we got a geometric column
274
- # and print the type and SRID
275
- if col . respond_to? ( :geometry_type )
276
- attrs << "#{ col . geometry_type } , #{ col . srid } "
277
- elsif col . respond_to? ( :geometric_type ) && col . geometric_type . present?
278
- attrs << "#{ col . geometric_type . to_s . downcase } , #{ col . srid } "
279
- end
280
-
281
- # Check if the column has indices and print "indexed" if true
282
- # If the index includes another column, print it too.
283
- if options [ :simple_indexes ] && klass . table_exists? # Check out if this column is indexed
284
- indices = retrieve_indexes_from_table ( klass )
285
- if indices = indices . select { |ind | ind . columns . include? col . name }
286
- indices . sort_by ( &:name ) . each do |ind |
287
- next if ind . columns . is_a? ( String )
288
- ind = ind . columns . reject! { |i | i == col . name }
289
- attrs << ( ind . empty? ? "indexed" : "indexed => [#{ ind . join ( ", " ) } ]" )
290
- end
291
- end
292
- end
293
-
294
- # Generate the column name optionally including column comments
252
+ attrs = get_attributes ( col , col_type , klass , options )
295
253
col_name = if with_comments? ( klass , options ) && col . comment
296
254
"#{ col . name } (#{ col . comment . gsub ( /\n / , "\\ n" ) } )"
297
255
else
@@ -812,7 +770,7 @@ def annotate_model_file(annotated, file, header, options)
812
770
begin
813
771
return false if /#{ SKIP_ANNOTATION_PREFIX } .*/ =~ ( File . exist? ( file ) ? File . read ( file ) : '' )
814
772
klass = get_model_class ( file )
815
- do_annotate = klass &&
773
+ do_annotate = klass . is_a? ( Class ) &&
816
774
klass < ActiveRecord ::Base &&
817
775
( !options [ :exclude_sti_subclasses ] || !( klass . superclass < ActiveRecord ::Base && klass . table_name == klass . superclass . table_name ) ) &&
818
776
!klass . abstract_class? &&
@@ -999,6 +957,55 @@ def ignored_translation_table_colums(klass)
999
957
foreign_column_name
1000
958
]
1001
959
end
960
+
961
+ ##
962
+ # Get the list of attributes that should be included in the annotation for
963
+ # a given column.
964
+ def get_attributes ( column , column_type , klass , options )
965
+ attrs = [ ]
966
+ attrs << "default(#{ schema_default ( klass , column ) } )" unless column . default . nil? || hide_default? ( column_type , options )
967
+ attrs << 'unsigned' if column . respond_to? ( :unsigned? ) && column . unsigned?
968
+ attrs << 'not null' unless column . null
969
+ 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 )
970
+
971
+ if column_type == 'decimal'
972
+ column_type << "(#{ column . precision } , #{ column . scale } )"
973
+ elsif !%w[ spatial geometry geography ] . include? ( column_type )
974
+ if column . limit && !options [ :format_yard ]
975
+ if column . limit . is_a? Array
976
+ attrs << "(#{ column . limit . join ( ', ' ) } )"
977
+ else
978
+ column_type << "(#{ column . limit } )" unless hide_limit? ( column_type , options )
979
+ end
980
+ end
981
+ end
982
+
983
+ # Check out if we got an array columnumn
984
+ attrs << 'is an Array' if column . respond_to? ( :array ) && column . array
985
+
986
+ # Check out if we got a geometric columnumn
987
+ # and print the type and SRID
988
+ if column . respond_to? ( :geometry_type )
989
+ attrs << "#{ column . geometry_type } , #{ column . srid } "
990
+ elsif column . respond_to? ( :geometric_type ) && column . geometric_type . present?
991
+ attrs << "#{ column . geometric_type . to_s . downcase } , #{ column . srid } "
992
+ end
993
+
994
+ # Check if the column has indices and print "indexed" if true
995
+ # If the index includes another column, print it too.
996
+ if options [ :simple_indexes ] && klass . table_exists? # Check out if this column is indexed
997
+ indices = retrieve_indexes_from_table ( klass )
998
+ if indices = indices . select { |ind | ind . columns . include? column . name }
999
+ indices . sort_by ( &:name ) . each do |ind |
1000
+ next if ind . columns . is_a? ( String )
1001
+ ind = ind . columns . reject! { |i | i == column . name }
1002
+ attrs << ( ind . empty? ? "indexed" : "indexed => [#{ ind . join ( ", " ) } ]" )
1003
+ end
1004
+ end
1005
+ end
1006
+
1007
+ attrs
1008
+ end
1002
1009
end
1003
1010
1004
1011
class BadModelFileError < LoadError
0 commit comments