SlideShare a Scribd company logo
1 of 24
Download to read offline
Rake
               The Familiar Stranger




Josh Nichols                           technicalpickles.com
What is Rake?
                  Ruby Make




Josh Nichols                  technicalpickles.com
Ruby what?
                A Ruby build tool




Josh Nichols                        technicalpickles.com
Which means...?
        A tool for automating tasks on the command
                   line using plain ol’ Ruby




Josh Nichols                           technicalpickles.com
What would you use Rake for?

      • Define a task
      • Make the task do something, maybe have it depend on
       other tasks
      • You’ve probably already used it
       • rake db:migrate
       • rake test



Josh Nichols                                 technicalpickles.com
Overview

      • The basics of Rake
      • Creating re-usable tasks for Rails
      • Creating re-usable tasks for any Ruby project
      • Testing




Josh Nichols                                   technicalpickles.com
Hello World

  # Rakefile (or rakefile or rakefile.rb or Rakefile.rb)

  require 'rake'

  desc quot;Hello World!quot;
  task :hello_world do
    puts quot;Hello World!quot;
  end




Josh Nichols                              technicalpickles.com
rake_demo $ rake -T
  (in /Users/nichoj/Projects/rake_demo)
  rake hello_world # Hello World!




Josh Nichols                              technicalpickles.com
rake_demo $ rake hello_world
   Hello World!




Josh Nichols                     technicalpickles.com
Defining tasks

      • desc
       • provide a human readable description for a task you're
         about to define
       • rake -T doesn’t show the task without this
      • task
       • provide a task name (can be a symbol or string)
       • provide a block
         • it's just ruby, yo
Josh Nichols                                   technicalpickles.com
Defining tasks: playing with the
                 filesystem
      • FileUtils module is included
       • cd, pwd, mkdir, mkdir_p, rmdir, ln, ln_s, ln_sf, cp, cp_r,
         mv, rm, rm_r, rm_rf, install, chmod, touch
      • FileList lets you specify a pattern for files/directories,
       then use it as an Enumerable
       • FileList['**/*.rb'].each {|f| puts f }



Josh Nichols                                       technicalpickles.com
Defining tasks: playing with the
                 filesystem
     require 'rake'

     desc quot;Clean the build directoryquot;
     task :clean do
       rm_r 'build'
     end

     desc quot;Make a backup of all ruby filesquot;
     task :backup do
       FileList['**/*.rb'].each do |f|
         cp f, quot;#{f}.bakquot;
       end
     end

Josh Nichols                                  technicalpickles.com
Dependencies between tasks

      • Easily declare a dependency on another task
      • A task that is depended on will only be run once... even
       if you run multiple times




Josh Nichols                                    technicalpickles.com
Dependencies between tasks

     require 'rake'

     task :give_presentation => :prepare_presentation do
       puts quot;So there's this thing called 'Rake'...quot;
     end

     task :prepare_presentation => :take_nap do
       puts quot;Just preparing, nothing to see here, move alongquot;
     end

     task :take_nap do
       puts quot;zzzzzzzzzzzzzzzzzzzquot;
     end



Josh Nichols                                   technicalpickles.com
rake_demo $ rake give_presentation
  (in /Users/nichoj/Projects/rake_demo)
  zzzzzzzzzzzzzzzzzzz
  Nothing to see here, move along
  So there's this thing called 'Rake'...




Josh Nichols                               technicalpickles.com
rake_demo $ rake take_nap give_presentation
   zzzzzzzzzzzzzzzzzzz
   Nothing to see here, move along
   So there's this thing called 'Rake'...




Josh Nichols                                technicalpickles.com
Group related tasks

      • Would be annoying to have a flat namespace
      • This isn’t C!
      • Rake has the concept of namespaces
      • rake namespace:task_name




Josh Nichols                                technicalpickles.com
Define a namespace

     require 'rake'

     namespace :presentation do
       task :give => :prepare do
         puts quot;So there's this thing called 'Rake'...quot;
       end

       task :prepare => :take_nap do
         puts quot;Just preparing, nothing to see here, move alongquot;
       end
     end



     task :take_nap do
       puts quot;zzzzzzzzzzzzzzzzzzzquot;
     end

Josh Nichols                                       technicalpickles.com
Extending tasks: more
                    dependencies
      • Just declare the task again, but with dependencies
      • These get added to whatever dependencies




Josh Nichols                                    technicalpickles.com
Moar dependencies
     namespace :presentation do
       task :give => :prepare do
         puts quot;So there's this thing called 'Rake'...quot;
       end

      task :prepare => :take_nap do
        puts quot;Just preparing, nothing to see here, move alongquot;
      end

       task :prepare => :watch_tv
     end

     task :watch_tv do
       puts quot;Previously on Heroes...quot;
     end

     task :take_nap do
       puts quot;zzzzzzzzzzzzzzzzzzzquot;
     end

Josh Nichols                                         technicalpickles.com
Using off the shelf tasks

      • Rake comes with a few bundled
       • Rake::GemPackageTask, Rake::PackageTask,
         Rake::RDocTask, Rake::TestTask
      • Just instantiate an instance in your Rakefile
     Rake::TestTask.new do |t|
       t.libs << 'lib'
       t.pattern = 'test/*_test.rb'
       t.verbose = false
     end



Josh Nichols                                     technicalpickles.com
Cue live coding
           ... cuz I ran out of time to make slides




Josh Nichols                               technicalpickles.com
Done, and done.


Josh Nichols         technicalpickles.com
What’s got two thumbs and is
      available for hire?
               http://technicalpickles.com/resume
                   josh@technicalpickles.com




Josh Nichols                              technicalpickles.com

More Related Content

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Rake: The Familiar Stranger

  • 1. Rake The Familiar Stranger Josh Nichols technicalpickles.com
  • 2. What is Rake? Ruby Make Josh Nichols technicalpickles.com
  • 3. Ruby what? A Ruby build tool Josh Nichols technicalpickles.com
  • 4. Which means...? A tool for automating tasks on the command line using plain ol’ Ruby Josh Nichols technicalpickles.com
  • 5. What would you use Rake for? • Define a task • Make the task do something, maybe have it depend on other tasks • You’ve probably already used it • rake db:migrate • rake test Josh Nichols technicalpickles.com
  • 6. Overview • The basics of Rake • Creating re-usable tasks for Rails • Creating re-usable tasks for any Ruby project • Testing Josh Nichols technicalpickles.com
  • 7. Hello World # Rakefile (or rakefile or rakefile.rb or Rakefile.rb) require 'rake' desc quot;Hello World!quot; task :hello_world do puts quot;Hello World!quot; end Josh Nichols technicalpickles.com
  • 8. rake_demo $ rake -T (in /Users/nichoj/Projects/rake_demo) rake hello_world # Hello World! Josh Nichols technicalpickles.com
  • 9. rake_demo $ rake hello_world Hello World! Josh Nichols technicalpickles.com
  • 10. Defining tasks • desc • provide a human readable description for a task you're about to define • rake -T doesn’t show the task without this • task • provide a task name (can be a symbol or string) • provide a block • it's just ruby, yo Josh Nichols technicalpickles.com
  • 11. Defining tasks: playing with the filesystem • FileUtils module is included • cd, pwd, mkdir, mkdir_p, rmdir, ln, ln_s, ln_sf, cp, cp_r, mv, rm, rm_r, rm_rf, install, chmod, touch • FileList lets you specify a pattern for files/directories, then use it as an Enumerable • FileList['**/*.rb'].each {|f| puts f } Josh Nichols technicalpickles.com
  • 12. Defining tasks: playing with the filesystem require 'rake' desc quot;Clean the build directoryquot; task :clean do rm_r 'build' end desc quot;Make a backup of all ruby filesquot; task :backup do FileList['**/*.rb'].each do |f| cp f, quot;#{f}.bakquot; end end Josh Nichols technicalpickles.com
  • 13. Dependencies between tasks • Easily declare a dependency on another task • A task that is depended on will only be run once... even if you run multiple times Josh Nichols technicalpickles.com
  • 14. Dependencies between tasks require 'rake' task :give_presentation => :prepare_presentation do puts quot;So there's this thing called 'Rake'...quot; end task :prepare_presentation => :take_nap do puts quot;Just preparing, nothing to see here, move alongquot; end task :take_nap do puts quot;zzzzzzzzzzzzzzzzzzzquot; end Josh Nichols technicalpickles.com
  • 15. rake_demo $ rake give_presentation (in /Users/nichoj/Projects/rake_demo) zzzzzzzzzzzzzzzzzzz Nothing to see here, move along So there's this thing called 'Rake'... Josh Nichols technicalpickles.com
  • 16. rake_demo $ rake take_nap give_presentation zzzzzzzzzzzzzzzzzzz Nothing to see here, move along So there's this thing called 'Rake'... Josh Nichols technicalpickles.com
  • 17. Group related tasks • Would be annoying to have a flat namespace • This isn’t C! • Rake has the concept of namespaces • rake namespace:task_name Josh Nichols technicalpickles.com
  • 18. Define a namespace require 'rake' namespace :presentation do task :give => :prepare do puts quot;So there's this thing called 'Rake'...quot; end task :prepare => :take_nap do puts quot;Just preparing, nothing to see here, move alongquot; end end task :take_nap do puts quot;zzzzzzzzzzzzzzzzzzzquot; end Josh Nichols technicalpickles.com
  • 19. Extending tasks: more dependencies • Just declare the task again, but with dependencies • These get added to whatever dependencies Josh Nichols technicalpickles.com
  • 20. Moar dependencies namespace :presentation do task :give => :prepare do puts quot;So there's this thing called 'Rake'...quot; end task :prepare => :take_nap do puts quot;Just preparing, nothing to see here, move alongquot; end task :prepare => :watch_tv end task :watch_tv do puts quot;Previously on Heroes...quot; end task :take_nap do puts quot;zzzzzzzzzzzzzzzzzzzquot; end Josh Nichols technicalpickles.com
  • 21. Using off the shelf tasks • Rake comes with a few bundled • Rake::GemPackageTask, Rake::PackageTask, Rake::RDocTask, Rake::TestTask • Just instantiate an instance in your Rakefile Rake::TestTask.new do |t| t.libs << 'lib' t.pattern = 'test/*_test.rb' t.verbose = false end Josh Nichols technicalpickles.com
  • 22. Cue live coding ... cuz I ran out of time to make slides Josh Nichols technicalpickles.com
  • 23. Done, and done. Josh Nichols technicalpickles.com
  • 24. What’s got two thumbs and is available for hire? http://technicalpickles.com/resume josh@technicalpickles.com Josh Nichols technicalpickles.com