Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow task loading from Rakefile for gems #66

Merged
merged 1 commit into from Dec 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions README.rdoc
Expand Up @@ -40,8 +40,7 @@ Also, if you pass the -r option, it'll annotate routes.rb with the output of "ra

Into Gemfile from Github:

gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'

gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'

Into environment gems From Rubygems.org:

Expand All @@ -54,7 +53,6 @@ Into environment gems from Github checkout:
rake build
sudo gem install pkg/annotate-*.gem


== USAGE

(If you used the Gemfile install, prefix the below commands with `bundle exec`.)
Expand Down Expand Up @@ -83,7 +81,21 @@ To automatically annotate after running 'rake db:migrate':
If you install annotate_models as a plugin, it will automatically
adjust your <tt>rake db:migrate</tt> tasks so that they update the
annotations in your model files for you once the migration is
completed.
completed. To get the same behavior from a gem, add the following to
your Rakefile:

require 'annotate/tasks'

To customize the behavior of annotate when it is running as a Rake
task, use the following (in your Rakefile or wherever):

ENV['position_in_class'] = "before"
ENV['position_in_fixture'] = "before"
ENV['show_indexes'] = "false"
ENV['include_version'] = "false"
ENV['exclude_tests'] = "false"
ENV['exclude_fixtures'] = "false"
ENV['skip_on_db_migrate'] = "false"

== OPTIONS

Expand Down
6 changes: 6 additions & 0 deletions lib/annotate/tasks.rb
@@ -0,0 +1,6 @@
require 'rubygems'
require 'rake'

# Make tasks visible for Rails also when used as gem.
Dir[File.join(File.dirname(__FILE__), '..', 'tasks', '**/*.rake')].each { |rake| load rake }
Dir[File.join(File.dirname(__FILE__), '..', '..', 'tasks', '**/*.rake')].each { |rake| load rake }
8 changes: 4 additions & 4 deletions tasks/migrate.rake
Expand Up @@ -13,9 +13,9 @@ namespace :db do
namespace :migrate do
[:change, :up, :down, :reset, :redo].each do |t|
task t do
Annotate::Migration.update_annotations
Annotate::Migration.update_annotations
end
end
end
end
end

Expand All @@ -24,9 +24,9 @@ module Annotate
@@working = false

def self.update_annotations
unless @@working
unless @@working || (ENV['skip_on_db_migrate'] =~ /(true|t|yes|y|1)$/i)
@@working = true
Rake::Task['annotate_models'].invoke
Rake::Task['annotate_models'].invoke
end
end
end
Expand Down