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 =
[]
@@run_without_git_diff =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, current, deploying) ⇒ ConditionalDeploy

Returns a new instance of ConditionalDeploy.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/capistrano-conditional/deploy.rb', line 37

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

  @git       = Git.open('.')
  @current   = get_object current, 'currently deployed'
  @deploying = get_object deploying, 'about to be deployed'
  return if @@run_without_git_diff

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

Class Method Details

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

Yields:

  • (_self)

Yield Parameters:



32
33
34
35
# File 'lib/capistrano-conditional/deploy.rb', line 32

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

.in_default_mode?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/capistrano-conditional/deploy.rb', line 16

def self.in_default_mode?
  @@run_without_git_diff
end

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



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

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



51
52
53
54
55
# File 'lib/capistrano-conditional/deploy.rb', line 51

def apply_conditions!
  screen_conditionals
  report_plan
  run_conditionals
end

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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/capistrano-conditional/deploy.rb', line 20

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