Commit 80facd4b by Satish Chauhan

modified code so that it will update only those models/fixtures which are…

modified code so that it will update only those models/fixtures which are affected by new migrations
parent b8180640
......@@ -22,8 +22,8 @@ module AnnotateModels
# to create a comment block containing a line for
# each column. The line contains the column name,
# the type (and length), and any optional attributes
def get_schema_info(klass, header)
info = "# #{header}\n#\n"
def get_schema_info(klass)
info = "# #{PREFIX}\n#\n"
info << "# Table name: #{klass.table_name}\n#\n"
max_size = klass.column_names.collect{|name| name.size}.max + 1
......@@ -82,8 +82,8 @@ module AnnotateModels
# on the columns and their types) and put it at the front
# of the model and fixture source files.
def annotate(klass, file, header,options={})
info = get_schema_info(klass, header)
def annotate(klass, file, options={})
info = get_schema_info(klass)
model_file_name = File.join(MODEL_DIR, file)
annotate_one_file(model_file_name, info, options.merge(:position=>(options[:position_in_class] || options[:position])))
......@@ -129,18 +129,12 @@ module AnnotateModels
# if its a subclass of ActiveRecord::Base,
# then pas it to the associated block
def do_annotations(options={})
header = PREFIX.dup
version = ActiveRecord::Migrator.current_version rescue 0
if version > 0
header << "\n# Schema version: #{version}"
end
annotated = []
get_model_files.each do |file|
begin
klass = get_model_class(file)
if klass < ActiveRecord::Base && !klass.abstract_class?
annotate(klass, file, header,options)
annotate(klass, file, options)
annotated << klass
end
rescue Exception => e
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment