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 ...@@ -22,8 +22,8 @@ module AnnotateModels
# to create a comment block containing a line for # to create a comment block containing a line for
# each column. The line contains the column name, # each column. The line contains the column name,
# the type (and length), and any optional attributes # the type (and length), and any optional attributes
def get_schema_info(klass, header) def get_schema_info(klass)
info = "# #{header}\n#\n" info = "# #{PREFIX}\n#\n"
info << "# Table name: #{klass.table_name}\n#\n" info << "# Table name: #{klass.table_name}\n#\n"
max_size = klass.column_names.collect{|name| name.size}.max + 1 max_size = klass.column_names.collect{|name| name.size}.max + 1
...@@ -82,8 +82,8 @@ module AnnotateModels ...@@ -82,8 +82,8 @@ module AnnotateModels
# on the columns and their types) and put it at the front # on the columns and their types) and put it at the front
# of the model and fixture source files. # of the model and fixture source files.
def annotate(klass, file, header,options={}) def annotate(klass, file, options={})
info = get_schema_info(klass, header) info = get_schema_info(klass)
model_file_name = File.join(MODEL_DIR, file) model_file_name = File.join(MODEL_DIR, file)
annotate_one_file(model_file_name, info, options.merge(:position=>(options[:position_in_class] || options[:position]))) annotate_one_file(model_file_name, info, options.merge(:position=>(options[:position_in_class] || options[:position])))
...@@ -129,18 +129,12 @@ module AnnotateModels ...@@ -129,18 +129,12 @@ module AnnotateModels
# if its a subclass of ActiveRecord::Base, # if its a subclass of ActiveRecord::Base,
# then pas it to the associated block # then pas it to the associated block
def do_annotations(options={}) def do_annotations(options={})
header = PREFIX.dup
version = ActiveRecord::Migrator.current_version rescue 0
if version > 0
header << "\n# Schema version: #{version}"
end
annotated = [] annotated = []
get_model_files.each do |file| get_model_files.each do |file|
begin begin
klass = get_model_class(file) klass = get_model_class(file)
if klass < ActiveRecord::Base && !klass.abstract_class? if klass < ActiveRecord::Base && !klass.abstract_class?
annotate(klass, file, header,options) annotate(klass, file, options)
annotated << klass annotated << klass
end end
rescue Exception => e 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