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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameterCollection

Returns a new instance of ParameterCollection.



23
24
25
# File 'lib/moonshot/parameter_collection.rb', line 23

def initialize
  @hash = {}
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



11
12
13
# File 'lib/moonshot/parameter_collection.rb', line 11

def hash
  @hash
end

Class Method Details

.from_template(template) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/moonshot/parameter_collection.rb', line 13

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



27
28
29
30
31
# File 'lib/moonshot/parameter_collection.rb', line 27

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

  @hash[key].set(value)
end

#add(parameter) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/moonshot/parameter_collection.rb', line 33

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.



41
42
43
44
45
# File 'lib/moonshot/parameter_collection.rb', line 41

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



47
48
49
50
51
# File 'lib/moonshot/parameter_collection.rb', line 47

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