Module: BeforeHook

Defined in:
lib/tasks/helpers/before_hook.rb

Instance Method Summary collapse

Instance Method Details

#before(*task_names, &new_task) ⇒ Object

The ‘before` hook for rake tasks. The code was taken from github.com/guillermo/rake-hooks/blob/master/lib/rake/hooks.rb#L2



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tasks/helpers/before_hook.rb', line 4

def before(*task_names, &new_task)
  task_names.each do |task_name|
    old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
    return unless old_task

    desc old_task.full_comment
    task task_name => old_task.prerequisites do
      new_task.call
      old_task.invoke
    end
  end
end