102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/schema_comments/schema_comment.rb', line 102
def dump(table)
root = nil
StringIO.open do |io|
YAML.dump(@table, io)
io.rewind
root = YAML.load(io)
end
= root['table_comments'] || {}
column_comments = root['column_comments'] || {}
raise YamlError, "Broken schame_comments.yml" unless root.is_a?(Hash)
root.extend(HashKeyOrderable)
root.key_order = %w(table_comments column_comments)
table_names = ActiveRecord::Base.connection.tables.sort - ['schema_migrations']
raise YamlError, "Broken schame_comments.yml" unless .is_a?(Hash)
.extend(HashKeyOrderable)
.key_order = table_names
raise YamlError, "Broken schame_comments.yml" unless column_comments.is_a?(Hash)
column_comments.extend(HashKeyOrderable)
column_comments.key_order = table_names
column_comments.each do |table_name, column_hash|
column_hash ||= {}
column_names = nil
begin
columns = ActiveRecord::Base.connection.columns_without_schema_comments(table_name)
column_names = columns.map(&:name)
rescue ActiveRecord::ActiveRecordError
column_names = column_hash.keys.sort
end
column_names.delete('id')
raise YamlError, "Broken schame_comments.yml" unless column_hash.is_a?(Hash)
column_hash.extend(HashKeyOrderable)
column_hash.key_order = column_names
end
root.to_yaml(@opt)
end
|