Commit d0fd9e37 by Nick Plante

add auto-annotate magic for ActiveRecord migrations in Rails

parent 8ecd23ee
...@@ -71,6 +71,11 @@ More options: ...@@ -71,6 +71,11 @@ More options:
-i, --show-indexes List the table's database indexes in the annotation -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 --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: == LICENSE:
Released under the same license as Ruby. No Support. No Warranty. Released under the same license as Ruby. No Support. No Warranty.
......
...@@ -169,7 +169,7 @@ module AnnotateModels ...@@ -169,7 +169,7 @@ module AnnotateModels
def get_model_files def get_model_files
models = ARGV.dup models = ARGV.dup
models.shift models.shift
models.reject!{|m| m.starts_with?("position=")} models.reject!{|m| m.match(/^(.*)=/)}
if models.empty? if models.empty?
Dir.chdir(model_dir) do Dir.chdir(model_dir) do
models = Dir["**/*.rb"] models = Dir["**/*.rb"]
...@@ -220,7 +220,7 @@ module AnnotateModels ...@@ -220,7 +220,7 @@ module AnnotateModels
end end
end end
rescue Exception => e rescue Exception => e
puts "Unable to annotate #{file}: #{e.message} (#{e.backtrace.first})" puts "Unable to annotate #{file}: #{e.message}"
end end
end end
if annotated.empty? 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