如何在挂钩进行耙任务之前将参数发送到

时间:2018-11-02 09:51:45

标签: ruby-on-rails hook rake-task

我想看到所有耙任务的“开始”和“完成”消息。

task :my_before_hook, [:name] => :environment do |_t, args|
  puts "Rake task #{args[:name]} started"
end

task :my_after_hook, [:name] => :environment do |_t, args|
  puts "Rake task #{args[:name]} finished"
end

task :my_test_task  => :environment do
  puts '--------- This is test task'
end

Rake.application.tasks.each do |tsk|
  next if [Rake::Task['my_before_hook'],
           Rake::Task['my_after_hook']].include?(tsk)

  tsk.enhance ['my_before_hook']

  tsk.enhance do
    Rake::Task['my_after_hook'].invoke(tsk.name)
  end
end

输出:

Rake task  started
--------- This is test task
Rake task my_test_task finished

问题在这里

tsk.enhance ['my_before_hook']

我不知道如何在挂接前将参数发送给

0 个答案:

没有答案