Class: Moonshot::StackParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/stack_parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default: nil, use_previous: false, description: '') ⇒ StackParameter

Returns a new instance of StackParameter.



7
8
9
10
11
12
13
# File 'lib/moonshot/stack_parameter.rb', line 7

def initialize(name, default: nil, use_previous: false, description: '')
  @default      = default
  @description  = description
  @name         = name
  @use_previous = use_previous
  @value        = nil
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



5
6
7
# File 'lib/moonshot/stack_parameter.rb', line 5

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/moonshot/stack_parameter.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/moonshot/stack_parameter.rb', line 5

def name
  @name
end

Instance Method Details

#default?Boolean

Does this Stack Parameter have a default value that will be used?

Returns:

  • (Boolean)


16
17
18
# File 'lib/moonshot/stack_parameter.rb', line 16

def default?
  !@default.nil?
end

#set(value) ⇒ Object



29
30
31
32
# File 'lib/moonshot/stack_parameter.rb', line 29

def set(value)
  @value = value
  @use_previous = false
end

#set?Boolean

Has the user provided a value for this parameter?

Returns:

  • (Boolean)


25
26
27
# File 'lib/moonshot/stack_parameter.rb', line 25

def set?
  !@value.nil?
end

#to_cfObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/moonshot/stack_parameter.rb', line 48

def to_cf
  result = { parameter_key: @name }

  if use_previous?
    result[:use_previous_value] = true
  else
    result[:parameter_value] = value
  end

  result
end

#use_previous!(value) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/moonshot/stack_parameter.rb', line 34

def use_previous!(value)
  raise "Value already set for StackParameter #{@name}, cannot use previous value!" if @value

  # Make the current value available to plugins.
  @value = value
  @use_previous = true
end

#use_previous?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/moonshot/stack_parameter.rb', line 20

def use_previous?
  @use_previous ? true : false
end

#valueObject



42
43
44
45
46
# File 'lib/moonshot/stack_parameter.rb', line 42

def value
  raise "No value set and no default for StackParameter #{@name}!" unless @value || default?

  @value || default
end