Class: Capistrano::Conditional::Unit

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

Overview

Stores the actual conditionals added by the user, including under what conditions the conditional should be applied (conditions) and what to do if that’s the case (block).

Created from ConditionalDeploy.register, the end user should never need to interact with it directly.

Constant Summary collapse

VALID_CONDITIONS =
[:any_match, :none_match, :if, :unless, :watchlist]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts, block) ⇒ Unit

Returns a new instance of Unit.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/capistrano-conditional/unit.rb', line 14

def initialize(name, opts, block)
  @name       = name
  @message    = opts.delete(:msg)
  @block      = block
  @conditions = {}
  @options    = {}

  opts.each do |k,v|
    if VALID_CONDITIONS.include?(k)
      @conditions[k] = v
    else
      @options[k] = v
    end
  end
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



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

def block
  @block
end

#conditionsObject

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#applies?(changed) ⇒ Boolean

Returns:

  • (Boolean)


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

def applies?(changed)
  @changed = changed
  return default? if ConditionalDeploy.in_default_mode?

  any_match_applies? && none_match_applies? && if_applies? && unless_applies?
end

#default?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/capistrano-conditional/unit.rb', line 37

def default?
  !!@options[:default]
end