When defining rake tasks, it is possible to use namespaces, like this:
namespace :demolition do task :fire_bazooka do puts "kaboom!" end end
This could be called like rake demolition:fire_bazooka
.
It is also possible to specify prerequisites for a task, like this:
# Single prerequisite task :fire_bazooka => :load_bazooka do .... # Multiple prerequisites task :fire_bazooka => [:safety_check, :load_bazooka]
But how can I use a namespaced task as a prerequisite? This, obviously, does not work:
task :photograph_destruction => :demolition:fire_bazooka
Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.
rake extension and are placed in Rails. root/lib/tasks . You can create these custom rake tasks with the bin/rails generate task command. If your need to interact with your application models, perform database queries and so on, your task should depend on the environment task, which will load your application code.
You already found the solution (name as a string).
You may extend this answer. There is no need to define namespaces and tasks with symbols. You can use Strings.
Doing this, you have the advantage of same type for definition and usage of task names.
Your example looks like this:
namespace 'demolition' do task 'fire_bazooka' do puts "kaboom!" end end task 'photograph_destruction' => "demolition:fire_bazooka" do puts "snapping pics! yay!" end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With