6 Rake Flashcards

1
Q

What is Rake?

A

Rake is a task runner. Rake will execute different tasks (basically a set of Ruby code) specified in any
file with a .rake extension from the command line. To run a rake task, just call the Rake command
with the name of your task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When do you use Rake?

A

Rake tasks are used when:
* Making a backup of your database
* Filling a database with data
* Running tests
* Gathering and reporting stats, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you add a description for Rake tasks?

A

You can use the desc method to describe your tasks. This is done on the line right above the task
definition. It’s also what gives you that nice output when you run rake -T to get a list of tasks. Tasks
are displayed in alphabetical order.
Rakefile.rb
desc ‘Make coffee’
task :make_coffee do
puts ‘Made a cup of coffee. Shakes are gone.’
end
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you execute a Rake task?

A

Rakefile.rb
namespace :morning do
task :turn_of_alarm
# …
end
$ rake morning:ready_for_the_day

Rakefile.rb
Rake::Task[‘morning:make_coffee’].execute
This always executes the task, but not its dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you pass arguments to a Rake task?

A

Rakefile.rb
namespace :morning do
desc ‘Make coffee’
task :make_coffee, :cups do |t, args|
cups = args.cups
puts “Made #{cups} cups of coffee. Shakes are gone.»
end
end
$ rake morning:make_coffee[2]
Made 2 cups of coffee. Shakes are gone.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly