rake速记

阅读更多
参考教程
 
  • http://jasonseifer.com/2010/04/06/rake-tutorial


hello rake
#rakefile.rb
task :default => [:hello]
task :hello do
  puts 'hello rake'
end
#$ rake 
#$ rake hello
#$ rake rakefile.rb


namespace
task :default => "morning:turn_of_alarm"
namespace :morning do
    task :turn_of_alarm do
      puts 'ding...'
    end
end
#$rake moring:turn_of_alarm


task description
desc "description of task "
task :hello do
end
#$ rake -T
#=>
#  rake hello # description of task



redefined task
task :default => 'morning:turn_of_alarm'
namespace :morning do
	desc "turn of alarm"
	task :turn_of_alarm do
		puts 'hello'
	end
end

namespace :morning do
	task :turn_of_alarm do
		puts 'world'
	end
end
#$ rake 
#=>
# hello
# world



invoking other task
task :default => 'task:world'
namespace :task do
	desc "hello world"
	task :hello do
		puts 'hello'
	end
end

namespace :task do
	task :world do
		puts '...'
		Rake::Task['task:hello'].invoke
		puts 'world'
	end
end
#Rake::Task['task:hello'].invoke(args.args_name)



task dependencies
task :default => 'task:world'
namespace :task do
	task :hello do
		puts 'hello'
	end
end

namespace :task do
	task :world => :hello do
		puts 'world'
	end
end


task arguments
task :say, [:name,:gender] do |t, args|
	args.with_defaults(:name=>'john',:gender=>'boy')
	puts "hello #{args.name}  #{args.gender}"
end 
#rake say[Lucy,girl]


multitask
Declare a task that performs its prerequisites in parallel. Multitasks does not guarantee that its prerequisites will execute in any given order (which is obvious when you think about it)
 multitask :deploy => [:deploy_gem, :deploy_rdoc]


mkdir task
 directory "tmp/abc"
#rake tmp/abc
#mkdir -p tmp/abc
 
#执行前会先建立tmp/abc
 task :task_a => "tmp/abc" do
 
 end


rule task
rule '.o' => ['.c'] do |t|
	sh "cp #{t.source} #{t.name}"
end
#touch a.c
#rake a.o
#cp a.c a.o
#t.source指a.c,  t.name是a.o

你可能感兴趣的:(Ruby,Rake)