• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rake: The Familiar Stranger
 

Rake: The Familiar Stranger

on

  • 4,986 views

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

Statistics

Views

Total Views
4,986
Views on SlideShare
3,989
Embed Views
997

Actions

Likes
9
Downloads
42
Comments
0

11 Embeds 997

http://technicalpickles.com 953
http://localhost 14
http://technicalpickles.dev 12
http://www.slideshare.net 8
http://translate.googleusercontent.com 3
http://webcache.googleusercontent.com 2
http://weekface.blogspot.com 1
http://www.mefeedia.com 1
http://feeds.feedburner.com 1
http://localhost:3000 1
http://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rake: The Familiar Stranger Rake: The Familiar Stranger Presentation Transcript

    • 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