Showing posts with label Rake. Show all posts
Showing posts with label Rake. Show all posts

Tuesday, April 20, 2010

Exclusively require and load tasks for rake with bundler

Rails アプリケーションで Bundler の Gemfile を使う場合、
group :test do
gem :rspec-rails
end

のように Rails.env に応じたグルーピングができます。

rake でしか使わない gem とそのタスクをこの仕組でできないかなと思って、bundler の issue トラッカーでヒントを貰ってなんとかできました。

Gemfile では
group :tasks do
gem 'ar_fixtures'
gem 'yaml_waml'
end


Rakefile では
Bundler.require(:tasks)
def load_task(task_file)
load Dir[Bundler.bundle_path + "gems/*/{tasks,rails/tasks,lib/tasks}/#{task_file}.rake"].first
end
load_task "ar_fixtures"


これで、
$ rake -T db:fixtures:dump
...
rake db:fixtures:dump # Dump data to the test/fixtures/ directory.