How do I run Rake tasks within a Ruby script?

前端 未结 4 1277
抹茶落季
抹茶落季 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:31

    This works with Rake version 10.0.3:

    require 'rake'
    app = Rake.application
    app.init
    # do this as many times as needed
    app.add_import 'some/other/file.rake'
    # this loads the Rakefile and other imports
    app.load_rakefile
    
    app['sometask'].invoke
    

    As knut said, use reenable if you want to invoke multiple times.

提交回复
热议问题