开发者

rake: Best way of handling an undefined parameter?

开发者 https://www.devze.com 2022-12-17 14:11 出处:网络
I\'ve got a rake task on a rails app that needs one pa开发者_Python百科rameter, called USER_ID. I think I\'d like to throw an exception that halts the execution. This is what my task looks like:

I've got a rake task on a rails app that needs one pa开发者_Python百科rameter, called USER_ID.

I think I'd like to throw an exception that halts the execution. This is what my task looks like:

desc "My rake task"
task :my_task => :envionment do

  user_id = ENV["USER_ID"] or # THROW SOMETHING HERE

  # ... do stuff with user_id

end

What code goes on THROW SOMETHING HERE?


What about something like this:

raise "Missing USER_ID!\n\ne.g: rake my_task USER_ID=6" if (user_id = ENV['USER_ID']).blank?
0

精彩评论

暂无评论...
验证码 换一张
取 消