Class: Moonshot::StackParameter
- Inherits:
-
Object
- Object
- Moonshot::StackParameter
- Defined in:
- lib/moonshot/stack_parameter.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#default? ⇒ Boolean
Does this Stack Parameter have a default value that will be used?.
-
#initialize(name, default: nil, use_previous: false, description: '') ⇒ StackParameter
constructor
A new instance of StackParameter.
- #set(value) ⇒ Object
-
#set? ⇒ Boolean
Has the user provided a value for this parameter?.
- #to_cf ⇒ Object
- #use_previous!(value) ⇒ Object
- #use_previous? ⇒ Boolean
- #value ⇒ Object
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/moonshot/stack_parameter.rb', line 5 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/moonshot/stack_parameter.rb', line 5 def description @description end |
#name ⇒ Object (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?
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?
25 26 27 |
# File 'lib/moonshot/stack_parameter.rb', line 25 def set? !@value.nil? end |
#to_cf ⇒ Object
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
20 21 22 |
# File 'lib/moonshot/stack_parameter.rb', line 20 def use_previous? @use_previous ? true : false end |
#value ⇒ Object
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 |