Class: ConditionalDeploy

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano-conditional/deploy.rb

Overview

This class handles the logic associated with checking if each conditional statement applies to a given deploy and, if so, applying them.

The only publicly-useful method is ConditionalDeploy.register, which is used in deploy.rb to add conditional elements (see README for details).

Constant Summary collapse

@@conditionals =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, current, deploying) ⇒ ConditionalDeploy

Returns a new instance of ConditionalDeploy.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capistrano-conditional/deploy.rb', line 32

def initialize(context, current, deploying)
  @context = context
  @log_method = :info # TODO: make this configurable

  @git       = Git.open('.')
  @working   = get_object 'HEAD'
  @current   = get_object current, 'currently deployed'
  @deploying = get_object deploying, 'about to be deployed'

  @diff    = @git.diff(current, deploying)
  @changed = @diff.stats[:files].keys.compact.sort
  @to_run  = []
end

Class Method Details

.configure(context) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
# File 'lib/capistrano-conditional/deploy.rb', line 27

def self.configure(context)
  @@deploy_context = context
  yield self
end

.register(name, opts, &block) ⇒ Object



10
11
12
13
# File 'lib/capistrano-conditional/deploy.rb', line 10

def self.register(name, opts, &block)
  raise("Already added a conditional with that name") if @@conditionals.any?{|c| c.name == name}
  @@conditionals << Capistrano::Conditional::Unit.new(name, opts, block)
end

Instance Method Details

#apply_conditions!Object



46
47
48
49
50
# File 'lib/capistrano-conditional/deploy.rb', line 46

def apply_conditions!
  screen_conditionals
  report_plan
  run_conditionals
end

#skip_task(name, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capistrano-conditional/deploy.rb', line 15

def skip_task(name, opts={})
  method = opts[:clear_hooks] ? :clear : :clear_actions
  msg = opts[:message] || "Skipping #{name} as preconditions to require it were not met"

  Rake::Task[name] && Rake::Task[name].send(method)

  # Need to create stub for method in case called from
  @@deploy_context.send(:task, name) do
    puts msg.cyan unless opts[:silent]
  end
end