Rake: The Familiar Stranger

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Rake: The Familiar Stranger - Presentation 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 \"Hello World!\" task :hello_world do puts \"Hello World!\" 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 \"Clean the build directory\" task :clean do rm_r 'build' end desc \"Make a backup of all ruby files\" task :backup do FileList['**/*.rb'].each do |f| cp f, \"#{f}.bak\" 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 \"So there's this thing called 'Rake'...\" end task :prepare_presentation => :take_nap do puts \"Just preparing, nothing to see here, move along\" end task :take_nap do puts \"zzzzzzzzzzzzzzzzzzz\" 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 \"So there's this thing called 'Rake'...\" end task :prepare => :take_nap do puts \"Just preparing, nothing to see here, move along\" end end task :take_nap do puts \"zzzzzzzzzzzzzzzzzzz\" 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 \"So there's this thing called 'Rake'...\" end task :prepare => :take_nap do puts \"Just preparing, nothing to see here, move along\" end task :prepare => :watch_tv end task :watch_tv do puts \"Previously on Heroes...\" end task :take_nap do puts \"zzzzzzzzzzzzzzzzzzz\" 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

    + Josh NicholsJosh Nichols, 11 months ago

    custom

    1286 views, 4 favs, 4 embeds more stats

    Rake is the Ruby build tool. Most Rubyists have at more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1286
      • 1224 on SlideShare
      • 62 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 23
    Most viewed embeds
    • 59 views on http://technicalpickles.com
    • 1 views on http://localhost:3000
    • 1 views on http://feeds.feedburner.com
    • 1 views on http://weekface.blogspot.com

    more

    All embeds
    • 59 views on http://technicalpickles.com
    • 1 views on http://localhost:3000
    • 1 views on http://feeds.feedburner.com
    • 1 views on http://weekface.blogspot.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories