Class: Moonshot::ParameterCollection
- Inherits:
-
Object
- Object
- Moonshot::ParameterCollection
- 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
- #[]=(key, value) ⇒ Object
- #add(parameter) ⇒ Object
-
#initialize ⇒ ParameterCollection
constructor
A new instance of ParameterCollection.
-
#missing_for_create ⇒ Object
What parameters are missing for a CreateStack call, where UsePreviousValue has no meaning.
- #missing_for_update ⇒ Object
Constructor Details
#initialize ⇒ ParameterCollection
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
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_create ⇒ Object
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_update ⇒ Object
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 |