Your SlideShare is downloading. ×
Rake: The Familiar Stranger
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rake: The Familiar Stranger

4,797

Published on

Rake is the Ruby build tool. Most Rubyists have at least used it in passing. But how well do you really know it? …

Rake is the Ruby build tool. Most Rubyists have at least used it in passing. But how well do you really know it?

This presentation was given by Josh Nichols at the December 2008 Boston Ruby Group meeting.

See the presentation at http://vimeo.com/2496890

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,797
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
45
Comments
0
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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

×