Can someone explain to me what the below task :seed
is doing? Specifically the []=>%w[]
section where ensure_review_app, environment, etc are listed? I recognize that db:seed
is seeding the database, but confused by what the others are doing.
task :seed, [] => %w[
ensure_review_app
environment
db:seed
seed:administrator
seed:widgets
] do
Rails.logger.tagged('Seed App') { |l| l.info("Finished seeding new Review App: #{ENV['HEROKU_APP_NAME']}") }
end
namespace :review_app do
desc 'Ensure environment is one we shish to spread seed in'
task :ensure_review_app do
abort 'This is not a Heroku Review App' unless review_app?
end
desc 'Seeds a review app with a subset of realistic-looking data'
task :seed, [] => %w[
ensure_review_app
environment
db:seed
seed:administrator
seed:widgets
] do
Rails.logger.tagged('Seed App') { |l| l.info("Finished seeding new Review App: #{ENV['HEROKU_APP_NAME']}") }
end
def review_app?
!!ENV['HEROKU_PARENT_APP_NAME']
end
end
As found here: https://gist.github.com/stevenharman/98576bf49b050b9e59fb26626b7cceff
I thought ensure_review_app might be a file, is it a heroku command?
The other things mentioned here are the prerequisites of the task you're looking at. I.e. they are other rake tasks that should be run prior to the :seed
task being run.
They're in a slightly odd format ( [] => %w[...]
) because the task is specifying that there are no arguments to the task. You can see this in the Tasks that Expect Parameters and Have Prerequisites section of the rake docs.
Often you'd see the prerequisites straight off the task name, e.g.:
task seed: %w[ensure_review_app environment db:seed ... ]
When you choose to run that task with rake review_app:seed
it will run all of the other prerequisite tasks first and then run the review_app:seed
task.
You can see the ensure_review_app
task in the longer snippet you posted. It's doing heroku stuff but it's just a rake task like any other.
You should be able to list any of the rake tasks using:
rake -T task_name
For tasks that don't have a description you might need to use -A
:
rake -A -T task_name