Class: Moonshot::ParameterCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/moonshot/parameter_collection.rb

Overview

A Rigid Hash-like structure that only accepts manipulation of parameters defined in the Stack template. Anything else results in an exception.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameterCollection

Returns a new instance of ParameterCollection.



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

def initialize
  @hash = {}
end

Class Method Details

.from_template(template) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/moonshot/parameter_collection.rb', line 10

def self.from_template(template)
  obj = new

  template.parameters.each do |stack_parameter|
    obj.add(stack_parameter)
  end

  obj
end

Instance Method Details

#[]=(key, value) ⇒ Object



24
25
26
27
28
# File 'lib/moonshot/parameter_collection.rb', line 24

def []=(key, value)
  raise "Invalid StackParameter #{key}!" unless @hash.key?(key)

  @hash[key].set(value)
end

#add(parameter) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
# File 'lib/moonshot/parameter_collection.rb', line 30

def add(parameter)
  raise ArgumentError, 'Can only add StackParameters!' unless parameter.is_a?(StackParameter)

  @hash[parameter.name] = parameter
end

#missing_for_createObject

What parameters are missing for a CreateStack call, where UsePreviousValue has no meaning.



38
39
40
41
42
# File 'lib/moonshot/parameter_collection.rb', line 38

def missing_for_create
  # If we haven't set a value, and there is no default, we can't
  # create the stack.
  @hash.values.select { |v| !v.set? && !v.default? }
end

#missing_for_updateObject



44
45
46
47
48
# File 'lib/moonshot/parameter_collection.rb', line 44

def missing_for_update
  # If we don't have a previous value to use, we haven't set a
  # value, and there is no default, we can't update a stack.
  @hash.values.select { |v| !v.set? && !v.default? && !v.use_previous? }
end