How do I return early from a rake task?

后端 未结 7 1490
一向
一向 2020-12-07 11:13

I have a rake task where I do some checks at the beginning, if one of the checks fails I would like to return early from the rake task, I don\'t want to execute any of the r

7条回答
  •  清歌不尽
    2020-12-07 11:26

    If you need to break out of multiple block levels, you can use fail.

    For example

    task :something do
      [1,2,3].each do |i|
        ...
        fail "some error" if ...
      end
    end
    

    (See https://stackoverflow.com/a/3753955/11543.)

提交回复
热议问题