How to call a Thor task multiple times?
- by deepak
Thor like Rake (and Make) has task management. If I call a task multiple times, it will effectively call the task only once. How can I call a task multiple times?
I tried modifying the @_invocations hash, but that did not work:
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