@@ -246,16 +246,7 @@ def get_schema_info(klass, header, options = {})
246
246
info << "# #{ '-' * ( max_size + md_names_overhead ) } | #{ '-' * md_type_allowance } | #{ '-' * 27 } \n "
247
247
end
248
248
249
- cols = if ignore_columns = options [ :ignore_columns ]
250
- klass . columns . reject do |col |
251
- col . name . match ( /#{ ignore_columns } / )
252
- end
253
- else
254
- klass . columns
255
- end
256
-
257
- cols = cols . sort_by ( &:name ) if options [ :sort ]
258
- cols = classified_sort ( cols ) if options [ :classified_sort ]
249
+ cols = columns ( klass , options )
259
250
cols . each do |col |
260
251
col_type = get_col_type ( col )
261
252
attrs = [ ]
@@ -903,13 +894,15 @@ def with_comments?(klass, options)
903
894
end
904
895
905
896
def max_schema_info_width ( klass , options )
897
+ cols = columns ( klass , options )
898
+
906
899
if with_comments? ( klass , options )
907
- max_size = klass . columns . map do |column |
900
+ max_size = cols . map do |column |
908
901
column . name . size + ( column . comment ? width ( column . comment ) : 0 )
909
902
end . max || 0
910
903
max_size += 2
911
904
else
912
- max_size = klass . column_names . map ( &:size ) . max
905
+ max_size = cols . map ( & :name ) . map ( &:size ) . max
913
906
end
914
907
max_size += options [ :format_rdoc ] ? 5 : 1
915
908
@@ -937,6 +930,55 @@ def mb_chars_ljust(string, length)
937
930
def non_ascii_length ( string )
938
931
string . to_s . chars . reject ( &:ascii_only? ) . length
939
932
end
933
+
934
+ def columns ( klass , options )
935
+ cols = klass . columns
936
+ cols += translated_columns ( klass )
937
+
938
+ if ignore_columns = options [ :ignore_columns ]
939
+ cols = cols . reject do |col |
940
+ col . name . match ( /#{ ignore_columns } / )
941
+ end
942
+ end
943
+
944
+ cols = cols . sort_by ( &:name ) if options [ :sort ]
945
+ cols = classified_sort ( cols ) if options [ :classified_sort ]
946
+
947
+ cols
948
+ end
949
+
950
+ ##
951
+ # Add columns managed by the globalize gem if this gem is being used.
952
+ def translated_columns ( klass )
953
+ return [ ] unless klass . respond_to? :translation_class
954
+
955
+ ignored_cols = ignored_translation_table_colums ( klass )
956
+ klass . translation_class . columns . reject do |col |
957
+ ignored_cols . include? col . name . to_sym
958
+ end
959
+ end
960
+
961
+ ##
962
+ # These are the columns that the globalize gem needs to work but
963
+ # are not necessary for the models to be displayed as annotations.
964
+ def ignored_translation_table_colums ( klass )
965
+ # Construct the foreign column name in the translations table
966
+ # eg. Model: Car, foreign column name: car_id
967
+ foreign_column_name = [
968
+ klass . translation_class . to_s
969
+ . gsub ( '::Translation' , '' ) . gsub ( '::' , '_' )
970
+ . downcase ,
971
+ '_id'
972
+ ] . join . to_sym
973
+
974
+ [
975
+ :id ,
976
+ :created_at ,
977
+ :updated_at ,
978
+ :locale ,
979
+ foreign_column_name
980
+ ]
981
+ end
940
982
end
941
983
942
984
class BadModelFileError < LoadError
0 commit comments