diff --git a/README.md b/README.md index d409a2b..a9c95ac 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1211 TILs and counting..._ +_1212 TILs and counting..._ --- @@ -1028,6 +1028,7 @@ _1211 TILs and counting..._ - [Silence The Output Of A Ruby Statement In Pry](ruby/silence-the-output-of-a-ruby-statement-in-pry.md) - [Single And Double Quoted String Notation](ruby/single-and-double-quoted-string-notation.md) - [Skip Specific CVEs When Auditing Your Bundle](ruby/skip-specific-cves-when-auditing-your-bundle.md) +- [Specify Dependencies For A Rake Task](ruby/specify-dependencies-for-a-rake-task.md) - [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md) - [String Interpolation With Instance Variables](ruby/string-interpolation-with-instance-variables.md) - [Summing Collections](ruby/summing-collections.md) diff --git a/ruby/specify-dependencies-for-a-rake-task.md b/ruby/specify-dependencies-for-a-rake-task.md new file mode 100644 index 0000000..74a7aa4 --- /dev/null +++ b/ruby/specify-dependencies-for-a-rake-task.md @@ -0,0 +1,37 @@ +# Specify Dependencies For A Rake Task + +Let's say you have rake task that performs some important business task. For +instance, a book seller might want a task that can tell them the top selling +books from a CSV report. + +```ruby +task :top_selling_books do + # read in CSV and process for top selling books +end +``` + +This works great if the CSV file already exists on the machine from which this +task is run. What if it isn't tho? + +The CSV is a prerequesite for this task. We explicitly define it as a +prerequisite using the task dependency syntax. + +```ruby +task :download_latest_book_sales_csv do + # saves a CSV of book sales +end + +task top_selling_books: :download_latest_book_sales_csv do + # read in CSV and process for top selling books +end +``` + +We can even define multiple task dependencies with an array. + +```ruby +task top_selling_books: [:download_latest_book_sales_csv, :clean_csv] do + # read in CSV and process for top selling books +end +``` + +[source](https://subscription.packtpub.com/book/hardware_and_creative/9781783280773/1/ch01lvl1sec13/task-dependencies-prerequisites)