Class: Stacker::Stack::Parameter

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/stacker/stack/parameter.rb

Overview

A Parameter represents a stack parameter. A parameter can be either a literal value (e.g. a string, number, or array) or a reference, otherwise known as a dependency. References parameter values are represented as hashes with a single key indicating the reference type. There is one exception to this rule; references to stack outputs are expressed as hashes with two keys, “Stack” and “Output”.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, region) ⇒ Parameter

Returns a new instance of Parameter.



20
21
22
23
24
25
26
27
# File 'lib/stacker/stack/parameter.rb', line 20

def initialize value, region
  @region = region
  @value = if value.is_a?(Array)
    value.map { |v| Parameter.new v, region }
  else
    value
  end
end

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



18
19
20
# File 'lib/stacker/stack/parameter.rb', line 18

def region
  @region
end

#valueObject (readonly)

Returns the value of attribute value.



18
19
20
# File 'lib/stacker/stack/parameter.rb', line 18

def value
  @value
end

Instance Method Details

#==(parameter) ⇒ Object



66
67
68
# File 'lib/stacker/stack/parameter.rb', line 66

def ==(parameter)
  parameter.value == value && parameter.region == region
end

#dependenciesObject



33
34
35
36
37
38
39
40
41
# File 'lib/stacker/stack/parameter.rb', line 33

def dependencies
  if dependency?
    [ to_s ]
  elsif value.is_a?(Array)
    value.map(&:dependencies).flatten
  else
    [ ]
  end
end

#dependency?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/stacker/stack/parameter.rb', line 29

def dependency?
  value.is_a?(Hash)
end

#resolvedObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stacker/stack/parameter.rb', line 43

def resolved
  if dependency?
    begin
      resolver.resolve
    rescue => err
      raise ParameterResolutionError.new value, err
    end
  elsif value.is_a?(Array)
    value.map(&:resolved).join ','
  else
    value
  end
end

#to_sObject



58
59
60
61
62
63
64
# File 'lib/stacker/stack/parameter.rb', line 58

def to_s
  if dependency?
    value.values.map(&:to_s).sort.join('.')
  else
    value.to_s
  end
end