Thor 和 Rake(和 Make)一样具有任务管理功能。如果我多次调用一个任务,它只会有效地调用该任务一次。如何多次调用任务?
我尝试修改@_invocations
哈希,但没有奏效:
require 'csv'
require './config/environment'
class MisReport < Thor
desc "all", "generate mysql and postgres mis"
def all
generate("pg_mis_report", "pg")
generate("mysql_mis_report", "mysql")
end
desc "generate", "generate mis report"
def generate(file_name = "mis_report_#{Time.now.to_s(:number)}", connection = "postgres")
if connection == "pg"
puts "== postgres database"
ActiveRecord::Base.establish_connection :development_mysql
else
puts "== mysql database"
ActiveRecord::Base.establish_connection :development
end
# generate MIS
puts
puts "mis file is at: #{file_path}"
end
end