当我运行Thor任务时,是否可以先调用特定任务?
我的Thorfile:
class Db < Thor desc "show_Version","some description ..." def show_version # <= needs a database connection puts ActiveRecord::Migrator.current_version end private def connect_to_database # <= call this always when a task from this file is executed # connect here to database end end
我可以在每个任务中编写“connect_to_database”方法,但这似乎不是很干.