Antzi
Antzi

Reputation: 13414

How to call a rake task programmatically - With arguments

I know we can run a task from within a rakefile like this:

Rake::Task['my_task'].execute()

How to do the same while passing arguments ?

Upvotes: 0

Views: 34

Answers (1)

Artur INTECH
Artur INTECH

Reputation: 7246

Provided you have the following task:

task :delete_user, [:name] do |t, args|
  puts "#{args.name} is being deleted."
end

You can call it using

Rake::Task['delete_user'].invoke('john')

or

Rake::Task['delete_user'].execute(Rake::TaskArguments.new([:name], ['john']))

Upvotes: 0

Related Questions