Class: Harrison::Deploy::Phase

Inherits:
Object
  • Object
show all
Defined in:
lib/harrison/deploy/phase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ Phase

Returns a new instance of Phase.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
10
11
# File 'lib/harrison/deploy/phase.rb', line 5

def initialize(name, &phase_config)
  self.name = name

  @conditions = Array.new

  yield self if block_given?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/harrison/deploy/phase.rb', line 3

def name
  @name
end

Instance Method Details

#_fail(context) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/harrison/deploy/phase.rb', line 40

def _fail(context)
  # Ensure all conditions eval to true for this context.
  return unless matches_context?(context)

  if @fail_block
    puts "[#{context.host}] Reverting \"#{self.name}\"..."
    @fail_block.call(context)
  end

end

#_run(context) ⇒ Object

These should only be invoked by the deploy action.



31
32
33
34
35
36
37
38
# File 'lib/harrison/deploy/phase.rb', line 31

def _run(context)
  return unless matches_context?(context)

  if @run_block
    puts "[#{context.host}] Executing \"#{self.name}\"..."
    @run_block.call(context)
  end
end

#add_condition(&block) ⇒ Object



13
14
15
# File 'lib/harrison/deploy/phase.rb', line 13

def add_condition(&block)
  @conditions << block
end

#matches_context?(context) ⇒ Boolean

Ensure all conditions eval to true for this context.

Returns:

  • (Boolean)


18
19
20
# File 'lib/harrison/deploy/phase.rb', line 18

def matches_context?(context)
  @conditions.all? { |cblock| cblock.call(context) }
end

#on_fail(&block) ⇒ Object



26
27
28
# File 'lib/harrison/deploy/phase.rb', line 26

def on_fail(&block)
  @fail_block = block
end

#on_run(&block) ⇒ Object



22
23
24
# File 'lib/harrison/deploy/phase.rb', line 22

def on_run(&block)
  @run_block = block
end