File: database.rake

package info (click to toggle)
ruby-activerecord-nulldb-adapter 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 248 kB
  • sloc: ruby: 833; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Sadly, we have to monkeypatch Rake because all of the Rails database tasks are
# hardcoded for specific adapters, with no extension points (!)
Rake::TaskManager.class_eval do
  def remove_task(task_name)
    @tasks.delete(task_name.to_s)
  end
end

def remove_task(task_name)
  Rake.application.remove_task(task_name)
end

def wrap_task(task_name, &wrapper)
  wrapped_task = Rake::Task[task_name]
  remove_task(Rake::Task.scope_name(Rake.application.current_scope,
                                    task_name))
  task(task_name) do
    wrapper.call(wrapped_task)
  end
end

namespace :db do
  namespace :test do
    wrap_task :purge do |wrapped_task|
      if ActiveRecord::Base.configurations["test"]["adapter"] == "nulldb"
        # NO-OP
      else
        wrapped_task.invoke
      end
    end
  end
end