How do I run Rake tasks within a Ruby script?

前端 未结 4 1286
抹茶落季
抹茶落季 2020-12-01 00:14

I have a Rakefile with a Rake task that I would normally call from the command line:

rake blog:post Title

I\'d like to write a

4条回答
  •  天涯浪人
    2020-12-01 00:27

    In a script with Rails loaded (e.g. rails runner script.rb)

    def rake(*tasks)
      tasks.each do |task|
        Rake.application[task].tap(&:invoke).tap(&:reenable)
      end
    end
    
    rake('db:migrate', 'cache:clear', 'cache:warmup')
    

提交回复
热议问题