require "rake"


module RakeTaskHelper
  # Railsの rake task を一度だけロードする
  def load_rails_tasks!
    return if defined?(@rails_tasks_loaded) && @rails_tasks_loaded
    @rails_tasks_loaded = true

    Rake.application = Rake::Application.new
    Rails.application.load_tasks
  end

  def run_rake_task(full_name)
    load_rails_tasks!

    task = Rake::Task[full_name]  # ここは rake[...] じゃなくて良い
    task.reenable
    task.invoke
  end
end
