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.
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
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.
23 24 25 |
# File 'lib/moonshot/parameter_collection.rb', line 23 def initialize @hash = {} end |
Instance Attribute Details
#hash ⇒ Object (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
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_create ⇒ Object
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_update ⇒ Object
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 |