Skip to content

Commit 61d148f

Browse files
committed
Add Specify Dependencies For A Rake Task as a Ruby TIL
1 parent 0715b70 commit 61d148f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1211 TILs and counting..._
13+
_1212 TILs and counting..._
1414

1515
---
1616

@@ -1028,6 +1028,7 @@ _1211 TILs and counting..._
10281028
- [Silence The Output Of A Ruby Statement In Pry](ruby/silence-the-output-of-a-ruby-statement-in-pry.md)
10291029
- [Single And Double Quoted String Notation](ruby/single-and-double-quoted-string-notation.md)
10301030
- [Skip Specific CVEs When Auditing Your Bundle](ruby/skip-specific-cves-when-auditing-your-bundle.md)
1031+
- [Specify Dependencies For A Rake Task](ruby/specify-dependencies-for-a-rake-task.md)
10311032
- [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md)
10321033
- [String Interpolation With Instance Variables](ruby/string-interpolation-with-instance-variables.md)
10331034
- [Summing Collections](ruby/summing-collections.md)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Specify Dependencies For A Rake Task
2+
3+
Let's say you have rake task that performs some important business task. For
4+
instance, a book seller might want a task that can tell them the top selling
5+
books from a CSV report.
6+
7+
```ruby
8+
task :top_selling_books do
9+
# read in CSV and process for top selling books
10+
end
11+
```
12+
13+
This works great if the CSV file already exists on the machine from which this
14+
task is run. What if it isn't tho?
15+
16+
The CSV is a prerequesite for this task. We explicitly define it as a
17+
prerequisite using the task dependency syntax.
18+
19+
```ruby
20+
task :download_latest_book_sales_csv do
21+
# saves a CSV of book sales
22+
end
23+
24+
task top_selling_books: :download_latest_book_sales_csv do
25+
# read in CSV and process for top selling books
26+
end
27+
```
28+
29+
We can even define multiple task dependencies with an array.
30+
31+
```ruby
32+
task top_selling_books: [:download_latest_book_sales_csv, :clean_csv] do
33+
# read in CSV and process for top selling books
34+
end
35+
```
36+
37+
[source](https://subscription.packtpub.com/book/hardware_and_creative/9781783280773/1/ch01lvl1sec13/task-dependencies-prerequisites)

0 commit comments

Comments
 (0)