Module: Capistrano::TaskEnhancements

Included in:
DSL
Defined in:
lib/capistrano/dsl/task_enhancements.rb

Instance Method Summary collapse

Instance Method Details

#after(task, post_task, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/capistrano/dsl/task_enhancements.rb', line 10

def after(task, post_task, *args, &block)
  Rake::Task.define_task(post_task, *args, &block) if block_given?
  task = Rake::Task[task]
  task.enhance do
    post = Rake.application.lookup(post_task, task.scope)
    raise ArgumentError, "Task #{post_task.inspect} not found" unless post
    post.invoke
  end
end

#before(task, prerequisite, *args, &block) ⇒ Object



5
6
7
8
# File 'lib/capistrano/dsl/task_enhancements.rb', line 5

def before(task, prerequisite, *args, &block)
  prerequisite = Rake::Task.define_task(prerequisite, *args, &block) if block_given?
  Rake::Task[task].enhance [prerequisite]
end

#default_tasksObject



47
48
49
# File 'lib/capistrano/dsl/task_enhancements.rb', line 47

def default_tasks
  %w{install}
end

#define_remote_file_task(task, target_roles) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/capistrano/dsl/task_enhancements.rb', line 20

def define_remote_file_task(task, target_roles)
  Capistrano::UploadTask.define_task(task) do |t|
    prerequisite_file = t.prerequisites.first
    file = shared_path.join(t.name)

    on roles(target_roles) do
      unless test "[ -f #{file.to_s.shellescape} ]"
        info "Uploading #{prerequisite_file} to #{file}"
        upload! File.open(prerequisite_file), file
      end
    end
  end
end

#deploying?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/capistrano/dsl/task_enhancements.rb', line 57

def deploying?
  fetch(:deploying, false)
end

#ensure_stageObject



34
35
36
37
38
39
40
41
# File 'lib/capistrano/dsl/task_enhancements.rb', line 34

def ensure_stage
  Rake::Task.define_task(:ensure_stage) do
    unless stage_set?
      puts t(:stage_not_set)
      exit 1
    end
  end
end

#exit_deploy_because_of_exception(ex) ⇒ Object



51
52
53
54
55
# File 'lib/capistrano/dsl/task_enhancements.rb', line 51

def exit_deploy_because_of_exception(ex)
  warn t(:deploy_failed, ex: ex.message)
  invoke "deploy:failed"
  exit(false)
end

#tasks_without_stage_dependencyObject



43
44
45
# File 'lib/capistrano/dsl/task_enhancements.rb', line 43

def tasks_without_stage_dependency
  stages + default_tasks
end