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(current, deploying) ⇒ ConditionalDeploy

Returns a new instance of ConditionalDeploy.



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

def initialize(current, deploying)
  @logger = Capistrano::Logger.new(:output => STDOUT)
  @logger.level = Capistrano::Logger::MAX_LEVEL

  @verbose = true
  @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 {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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

def self.configure
  yield self
end

.monitor_migrations(context) ⇒ Object



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

def self.monitor_migrations(context)
  if ARGV.any?{|v| v['deploy:migrations']} # If running deploy:migrations
    # If there weren't any changes to migrations or the schema file, then abort the deploy
    ConditionalDeploy.register :unneeded_migrations, :none_match => ['db/schema.rb', 'db/migrate'] do
      context.send :abort, "You're running migrations, but it doesn't look like you need to!"
    end
  else # If NOT running deploy:migrations
    # If there were changes to migration files, run migrations as part of the deployment
    ConditionalDeploy.register :forgotten_migrations, :any_match => ['db/schema.rb', 'db/migrate'], :msg => "Forgot to run migrations? It's cool, we'll do it for you." do
      context.after "deploy:update_code", "deploy:migrate"
    end
  end
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



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

def apply_conditions!
  screen_conditionals
  report_plan
  run_conditionals
end