17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/migration_comments/annotate_models.rb', line 17
def (klass, info)
table_name = klass.table_name
adapter = klass.connection
= adapter.(table_name)
column_comments = adapter.retrieve_column_comments(table_name)
lines = []
info.each_line{|l| lines << l.chomp}
column_regex = /^#\s+(\w+)\s+:\w+/
len = lines.select{|l| l =~ column_regex}.map{|l| l.length}.max
lines.each do |line|
if line =~ /# Table name: |# table \+\w+\+ /
line << " # #{}" if
elsif line =~ column_regex
= column_comments[$1.to_sym]
line << " " * (len - line.length) << " # #{}" if
end
end
lines.join($/) + $/
end
|