3. Topics
‣ Making a Rake Task
Monday, August 16, 2010
4. Topics
‣ Making a Rake Task
‣ With Namespaces
Monday, August 16, 2010
5. Topics
‣ Making a Rake Task
‣ With Namespaces
‣ Accepting Arguments
Monday, August 16, 2010
6. Topics
‣ Making a Rake Task
‣ With Namespaces
‣ Accepting Arguments
‣ With Dependencies
Monday, August 16, 2010
7. Topics
‣ Making a Rake Task
‣ With Namespaces
‣ Accepting Arguments
‣ With Dependencies
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
8. Topics
‣ Making a Rake Task
‣ With Namespaces
‣ Accepting Arguments
‣ With Dependencies
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
9. Topics
‣ Making a Rake Task ‣ Multiple dependencies
‣ With Namespaces
‣ Accepting Arguments
‣ With Dependencies
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
10. Topics
‣ Making a Rake Task ‣ Multiple dependencies
‣ With Namespaces ‣ Instance variables
‣ Accepting Arguments
‣ With Dependencies
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
11. Topics
‣ Making a Rake Task ‣ Multiple dependencies
‣ With Namespaces ‣ Instance variables
‣ Accepting Arguments ‣ That reads from
STDIN
‣ With Dependencies
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
12. Topics
‣ Making a Rake Task ‣ Multiple dependencies
‣ With Namespaces ‣ Instance variables
‣ Accepting Arguments ‣ That reads from
STDIN
‣ With Dependencies
‣ Interact with Rails
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
13. Topics
‣ Making a Rake Task ‣ Multiple dependencies
‣ With Namespaces ‣ Instance variables
THOR
‣ Accepting Arguments
‣ With Dependencies
‣ That reads from
STDIN
‣ Interact with Rails
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
14. Getting Started
‣ Making a Rake Task
‣ Accepting Arguments
‣ With Dependencies
Monday, August 16, 2010
15. task :greeting do
puts 'Hello Ruby Community!'
end
intro-to-rake/01/Rakefile
$ rake -T
(in /Users/Dane/Projects/intro-to-rake/01)
$ rake greeting
(in /Users/Dane/Projects/intro-to-rake/01)
Hello Ruby Community!
intro-to-rake/01/command.sh
Monday, August 16, 2010 Sub-Title
16. desc 'Greets the Ruby Community' # <-- key point
task :greeting do
puts 'Hello Ruby Community!'
end
intro-to-rake/02/Rakefile
$ rake -T
(in /Users/Dane/Projects/intro-to-rake/02)
rake greeting # Greets the Ruby Community
intro-to-rake/02/command.sh
Monday, August 16, 2010 Sub-Title
17. desc 'Greets the Ruby Community'
task :greeting, :name do |command, args| # <-- key point
puts "command: #{command}" # <-- key point
puts "Hello #{args[:name]}!" # <-- key point
end
intro-to-rake/03/Rakefile
$ rake -T
(in /Users/Dane/Projects/intro-to-rake/03)
rake greeting[name] # Greets the Ruby Community
$ rake greeting[‘Ruby Community’]
(in /Users/Dane/Projects/intro-to-rake/03)
command: greeting
Hello Ruby Community!
intro-to-rake/03/command.sh
Monday, August 16, 2010 Sub-Title
18. desc 'Greets the Ruby Community'
task :greeting, :first, :second do |command, args|# <- key
point
puts "command: #{command}"
puts "Hello #{args[:first]} #{args[:second]}!"
end
intro-to-rake/04/command.sh
$ rake greeting[Ruby,Community]
(in /Users/Dane/Projects/intro-to-rake/04)
command: greeting
Hello Ruby Community!
intro-to-rake/04/command.sh
Monday, August 16, 2010 Sub-Title
19. desc 'Greets the Ruby Community'
task :greeting, :name do |command, args|
puts "Hello #{args[:name]}!"
end
desc 'Ask how you are doing'
task :question => :greeting do # <-- key point
puts 'How are you?'
end
intro-to-rake/05/Rakefile
$ rake question
(in /Users/Dane/Projects/intro-to-rake/05)
Hello !
How are you?
intro-to-rake/05/command.sh
Monday, August 16, 2010 Sub-Title
20. desc 'Greets the Ruby Community'
task :greeting, :name do |command, args|
puts "Hello #{args[:name]}!"
end
desc 'Ask how you are doing'
task :question do
Rake::Task[:greeting].invoke('Ruby Community') # <-- key
point
puts 'How are you?'
intro-to-rake/06/Rakefile
$ rake question
(in /Users/Dane/Projects/intro-to-rake/06)
Hello Ruby Community!
How are you?
intro-to-rake/06/command.sh
Monday, August 16, 2010 Sub-Title
21. desc 'Greets the Ruby Community'
task :greeting, :name do |command, args|
puts "Hello #{args[:name]}!"
Rake::Task[:greeting].reenable # <-- key point
end
desc 'Ask how you are doing'
task :question do
Rake::Task[:greeting].invoke('Ruby Community')
Rake::Task[:greeting].invoke('Ruby Community')
puts 'How are you?'
end
intro-to-rake/07/Rakefile
Monday, August 16, 2010
22. $ rake question
(in /Users/Dane/Projects/intro-to-rake/07)
Hello Ruby Community!
Hello Ruby Community!
How are you?
$ rake greeting[‘Ruby Community’]
(in /Users/Dane/Projects/intro-to-rake/07)
Hello Ruby Community!
intro-to-rake/07/command.sh
Monday, August 16, 2010
23. desc 'Greets the Ruby Community'
task :greeting do |command, args|
puts "Hello #{args[:name]}!"
end
desc 'Ask how you are doing'
task :question do
Rake::Task[:greeting].execute(:name => 'Ruby Community') # <--
puts 'How are you?'
end
intro-to-rake/08/Rakefile
$ rake question
(in /Users/Dane/Projects/intro-to-rake/07)
Hello Ruby Community!
How are you?
$ rake greeting['Ruby Community']
(in /Users/Dane/Projects/intro-to-rake/07)
Hello !
intro-to-rake/08/command.sh
Monday, August 16, 2010 Sub-Title
26. desc 'Will display "first"'
task :first do
puts '** First **'
end
desc 'Will display "second"'
task :second => :first do # <-- key point
puts '** Second **'
end
desc 'Will display "third"'
task :third do
Rake::Task[:second].invoke # <-- key point
puts '** Third **'
end
intro-to-rake/09/Rakefile
Monday, August 16, 2010
27. $ rake first
(in /Users/Dane/Projects/intro-to-rake/08)
** First **
$ rake second
(in /Users/Dane/Projects/intro-to-rake/08)
** First **
** Second **
$ rake third
(in /Users/Dane/Projects/intro-to-rake/08)
** First **
** Second **
** Third **
intro-to-rake/09/command.sh
Monday, August 16, 2010
28. desc 'Will display "first"'
task :first do
puts '** First **'
end
desc 'Will display "second"'
task :second => :first do # <-- key point
puts '** Second **'
end
desc 'Will display "third"'
task :third do
Rake::Task[:second].execute # <-- key point
puts '** Third **'
end
intro-to-rake/10/Rakefile
Monday, August 16, 2010
29. $ rake first
(in /Users/Dane/Projects/intro-to-rake/09)
** First **
$ rake second
(in /Users/Dane/Projects/intro-to-rake/09)
** First **
** Second **
$ rake third
(in /Users/Dane/Projects/intro-to-rake/09)
** Second **
** Third **
intro-to-rake/10/command.sh
Monday, August 16, 2010
30. Getting Fancy
‣ With Namespaces
‣ Dependencies from
other Namespaces
Monday, August 16, 2010
31. namespace :numbers do # <-- key point
desc 'Will display "first"'
task :first do
puts '** First **'
end
desc 'Will display "second"'
task :second => :first do # <-- key point
puts '** Second **'
end
end
intro-to-rake/11/Rakefile
Monday, August 16, 2010
32. $ rake -T
(in /Users/Dane/Projects/intro-to-rake/10)
rake numbers:first # Will display "first"
rake numbers:second # Will display "second"
$ rake numbers:first
(in /Users/Dane/Projects/intro-to-rake/10)
** First **
$ rake numbers:second
(in /Users/Dane/Projects/intro-to-rake/10)
** First **
** Second **
intro-to-rake/11/command.sh
Monday, August 16, 2010
33. namespace :numbers do
desc 'Will display "first"'
task :first do
puts '** First **'
end
desc 'Will display "second"'
task :second do
Rake::Task['numbers:first'].invoke # <-- key point
puts '** Second **'
end
end
intro-to-rake/12/Rakefile
Monday, August 16, 2010
34. $ rake numbers:first
(in /Users/Dane/Projects/intro-to-rake/11)
** First **
$ rake numbers:second
(in /Users/Dane/Projects/intro-to-rake/11)
** First **
** Second **
intro-to-rake/12/command.sh
Monday, August 16, 2010
35. namespace :group do # <-- key point
namespace :numbers do
desc 'Will display "first"'
task :first do
puts '** First **'
end
desc 'Will display "second"'
task :second => :first do # <-- key point
puts '** Second **'
end
end
end
intro-to-rake/13/Rakefile
Monday, August 16, 2010
36. $ rake -T
(in /Users/Dane/Projects/intro-to-rake/12)
rake group:numbers:first # Will display "first"
rake group:numbers:second # Will display "second"
$ rake group:numbers:first
(in /Users/Dane/Projects/intro-to-rake/12)
** First **
$ rake group:numbers:second
(in /Users/Dane/Projects/intro-to-rake/12)
** First **
** Second **
intro-to-rake/13/command.sh
Monday, August 16, 2010
37. namespace :group do
namespace :numbers do
desc 'Will display "first"'
task :first do
puts '** First **'
end
end
end
desc 'Will display "second"'
task :second => 'group:numbers:first' do # <-- key point
puts '** Second **'
end
intro-to-rake/14/Rakefile
Monday, August 16, 2010
38. $ rake group:numbers:first
(in /Users/Dane/Projects/intro-to-rake/13)
** First **
$ rake second
(in /Users/Dane/Projects/intro-to-rake/13)
** First **
** Second **
intro-to-rake/14/command.sh
Monday, August 16, 2010
39. namespace :group do
desc 'This will displays numbers'
task :numbers do # <-- key point
puts "*** "+(1..10).to_a.join(' ')+" ***"
end
namespace :numbers do # <-- key point
desc 'Will display "first"'
task :first do
puts '** First **'
end
end
end
intro-to-rake/15/Rakefile
Monday, August 16, 2010
40. $ rake group:numbers
(in /Users/Dane/Projects/intro-to-rake/15)
*** 1 2 3 4 5 6 7 8 9 10 ***
$ rake group:numbers:first
(in /Users/Dane/Projects/intro-to-rake/15)
** First **
intro-to-rake/15/command.sh
Monday, August 16, 2010
42. Now We’re Fancy
‣ Instance variables
‣ Multiple dependencies
Monday, August 16, 2010
43. task :first do
@name = 'Ruby Community' # <-- key point
end
task :second => :first do
puts "*** #{@name} ***" # <-- key point
end
intro-to-rake/16/Rakefile
$ rake second
(in /Users/Dane/Projects/intro-to-rake/16)
*** Ruby Community ***
intro-to-rake/16/command.sh
Monday, August 16, 2010 Sub-Title
44. task :first do
@name = 'Ruby Community' # <-- key point
end
task :second do
@name = 'Nooby Community' # <-- key point
end
task :third => [:first, :second] do # <-- key point
puts "*** #{@name} ***" # <-- key point
end
intro-to-rake/17/Rakefile
Monday, August 16, 2010
45. $ rake third
(in /Users/Dane/Projects/intro-to-rake/17)
*** Nooby Community ***
intro-to-rake/17/command.sh
Monday, August 16, 2010
46. Get Crazy
‣ Interact with Rails
Monday, August 16, 2010
48. Get Calm
‣ Reading from STDIN
Monday, August 16, 2010
49. require 'rubygems'
require 'highline/import'
task :bootstrap do
user = ask('What is your username? ')
pass = ask('What is your password? ') { |q| q.echo =
false }
puts "Username: #{user}"
puts "Password: #{pass}"
end
intro-to-rake/18/Rakefile
Monday, August 16, 2010
50. $ rake bootstrap
(in /Users/Dane/Projects/intro-to-rake/18)
What is your username? dharrigan
What is your password?
Username: dharrigan
Password: password
intro-to-rake/18/command.sh
Monday, August 16, 2010
52. class MyApp < Thor
desc :first, 'This is my first task'
def first
say 'First!'
end
desc :second, 'This is my second task'
def second
invoke :first
say 'second!'
end
end
intro-to-rake/19/Thorfile
Monday, August 16, 2010
53. $ thor list
my_app
------
<path>/thor my_app:first # This is my first task
<path>/thor my_app:second # This is my second task
$ thor my_app:second
First!
second!
intro-to-rake/19/command.sh
Monday, August 16, 2010
54. class MyApp < Thor
desc :first, 'This is my first task'
def first(name)
say name
say 'First!'
end
desc :second, 'This is my second task'
def second
invoke :first, ['Ruby Community'] # <-- key point
say 'second!'
end
end
intro-to-rake/20/Thorfile
Monday, August 16, 2010
55. $ thor my_app:first 'Ruby Community'
Ruby Community
First!
$ thor my_app:second
Ruby Community
First!
second!
intro-to-rake/20/command.sh
Monday, August 16, 2010
56. class MyApp < Thor
desc :first, 'This is my first task'
method_options :name => :string # <-- key point
def first
say options[:name] # <-- key point
say 'First!'
end
end
intro-to-rake/21/Thorfile
$ thor my_app:first --name 'Ruby Community'
Ruby Community
First!
intro-to-rake/21/command.sh
Monday, August 16, 2010 Sub-Title
57. $ rake about
Dane Harrigan
dane.harrigan@gmail.com
Twitter: @daneharrigan
Github: http://github.com/daneharrigan
Website: http://codequietly.com
---
Code examples are available at Github:
http://github.com/daneharrigan/presentations/
intro-to-rake/command.sh
Monday, August 16, 2010