How to call a Thor task multiple times?

Posted by deepak on Stack Overflow See other posts from Stack Overflow or by deepak
Published on 2012-10-05T15:19:37Z Indexed on 2012/10/05 15:37 UTC
Read the original article Hit count: 324

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rake