Commit d0fd9e37 by Nick Plante

add auto-annotate magic for ActiveRecord migrations in Rails

parent 8ecd23ee
......@@ -71,6 +71,11 @@ More options:
-i, --show-indexes List the table's database indexes in the annotation
--model-dir dir Annotate model files stored in dir rather than app/models
If you install annotate_models as a plugin, it will automatically
adjust your <tt>rake migrate</tt> tasks so that they update the
annotations in your model files for you once the migration is
completed.
== LICENSE:
Released under the same license as Ruby. No Support. No Warranty.
......
......@@ -169,7 +169,7 @@ module AnnotateModels
def get_model_files
models = ARGV.dup
models.shift
models.reject!{|m| m.starts_with?("position=")}
models.reject!{|m| m.match(/^(.*)=/)}
if models.empty?
Dir.chdir(model_dir) do
models = Dir["**/*.rb"]
......@@ -220,7 +220,7 @@ module AnnotateModels
end
end
rescue Exception => e
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})"
puts "Unable to annotate #{file}: #{e.message}"
end
end
if annotated.empty?
......
# append annotations to Rake tasks (for Rails)
namespace :db do
task :migrate do
Annotate::Migration.update_annotations
end
namespace :migrate do
[:up, :down, :reset, :redo].each do |t|
task t do
Annotate::Migration.update_annotations
end
end
end
end
module Annotate
class Migration
@@working = false
def self.update_annotations
unless @@working
@@working = true
Rake::Task['annotate_models'].invoke
end
end
end
end
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