How to call Rake tasks that are defined in the standard Rakefile from an other Ruby script?

前端 未结 2 541
小蘑菇
小蘑菇 2021-02-04 07:41

Is it possible to call a task which is defined in a Rakefile - not in somefile.rake - from an other Ruby script?

I was hoping that creating a n

2条回答
  •  一个人的身影
    2021-02-04 08:41

    You forgot to add your new rake to the current Rake Application:

    $LOAD_PATH.unshift File.dirname(__FILE__)
    
    require 'rake'
    require 'pp'
    
    rake = Rake::Application.new
    Rake.application = rake
    rake.init
    rake.load_rakefile
    
    rake[:hello].invoke
    

    or just

    $LOAD_PATH.unshift File.dirname(__FILE__)
    require 'rake'
    require 'pp'
    
    Rake.application.init
    Rake.application.load_rakefile
    
    Rake.application[:hello].invoke
    

提交回复
热议问题