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
12
13
14
15
# File 'lib/harrison/deploy/phase.rb', line 5

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

  @conditions = Array.new

  @limit = nil
  @_run_count = 0
  @_fail_count = 0

  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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/harrison/deploy/phase.rb', line 54

def _fail(context)
  # Ensure limit has not been met.
  return unless @limit.nil? || @_fail_count < @limit

  # 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)
    @_fail_count += 1
  end

end

#_run(context) ⇒ Object

These should only be invoked by the deploy action.



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

def _run(context)
  # Ensure limit has not been met.
  return unless @limit.nil? || @_run_count < @limit

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

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

#add_condition(&block) ⇒ Object



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

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

#matches_context?(context) ⇒ Boolean

Check if all conditions eval to true for this context.

Returns:

  • (Boolean)


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

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

#on_fail(&block) ⇒ Object



35
36
37
# File 'lib/harrison/deploy/phase.rb', line 35

def on_fail(&block)
  @fail_block = block
end

#on_run(&block) ⇒ Object



31
32
33
# File 'lib/harrison/deploy/phase.rb', line 31

def on_run(&block)
  @run_block = block
end

#set_limit(n) ⇒ Object

Limit the number of times this phase is invoked per deployment.



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

def set_limit(n)
  @limit = n
end