1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

add before/after to dsl

This commit is contained in:
seenmyfate 2013-02-08 09:15:10 +00:00
parent de6367af4e
commit ad9da10c32
3 changed files with 42 additions and 3 deletions

View file

@ -16,7 +16,7 @@ TODO:
- [x] basic 'capistrano/deploy' noop example
- [x] don't care too much about testing at this point (rspec included for my reference)
- [ ] before/after task hooks
- [x] before/after task hooks
- [ ] consider requiring default tasks via configuration (strategy?) rather than Capfile
- [ ] write more default tasks
- [ ] handle multiple stage file generation
@ -40,3 +40,30 @@ Capify:
$ cap -vT
$ cap deploy
## Before / After
Where calling on the same task name, executed in order of inclusion
# call an existing task
before :starting, :ensure_user
after :finishing, :notify
# or define in block
before :starting, :ensure_user do
#
end
after :finishing, :notify do
#
end

View file

@ -1,8 +1,20 @@
module Capistrano
module DSL
def before(task, prerequisite, *args, &block)
rerequisite = Rake::Task.define_task(prerequisite, *args, &block) if block_given?
Rake::Task[task].enhance [prerequisite]
end
def after(task, post_task, *args, &block)
post_task = Rake::Task.define_task(post_task, *args, &block) if block_given?
Rake::Task[task].enhance do
invoke(post_task)
end
end
def invoke(task)
::Rake::Task["deploy:#{task}"].invoke
Rake::Task[task].invoke
end
def fetch(key)

View file

@ -45,7 +45,7 @@ end
desc "Deploy"
task :deploy do
%w{starting start update finalize restart finishing finished}.each do |stage|
invoke stage
invoke "deploy:#{stage}"
end
end
task default: :deploy