Class: Bolt::PAL::YamlPlan::Parameter
- Inherits:
-
Object
- Object
- Bolt::PAL::YamlPlan::Parameter
- Defined in:
- lib/bolt/pal/yaml_plan/parameter.rb
Constant Summary collapse
- PARAMETER_KEYS =
Set['type', 'default', 'description']
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type_expr ⇒ Object
readonly
Returns the value of attribute type_expr.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #captures_rest ⇒ Object
-
#initialize(param, definition) ⇒ Parameter
constructor
A new instance of Parameter.
- #transpile ⇒ Object
- #validate_param(param, definition) ⇒ Object
Constructor Details
#initialize(param, definition) ⇒ Parameter
Returns a new instance of Parameter.
11 12 13 14 15 16 17 18 19 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 11 def initialize(param, definition) definition ||= {} validate_param(param, definition) @name = param @value = definition['default'] @type_expr = Puppet::Pops::Types::TypeParser.singleton.parse(definition['type']) if definition['type'] @description = definition['description'] end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 7 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 7 def name @name end |
#type_expr ⇒ Object (readonly)
Returns the value of attribute type_expr.
7 8 9 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 7 def type_expr @type_expr end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 7 def value @value end |
Instance Method Details
#captures_rest ⇒ Object
35 36 37 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 35 def captures_rest false end |
#transpile ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 39 def transpile result = String.new result << "\n\s\s" # Param type if @type_expr.respond_to?(:type_string) result << @type_expr.type_string + " " elsif !@type_expr.nil? result << @type_expr.to_s + " " end # Param name result << "$#{@name}" # Param default if @value default = @type_expr.to_s =~ /String/ ? "'#{@value}'" : @value result << " = #{default}" end result end |
#validate_param(param, definition) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bolt/pal/yaml_plan/parameter.rb', line 21 def validate_param(param, definition) unless param.is_a?(String) && param.match?(Bolt::PAL::YamlPlan::VAR_NAME_PATTERN) raise Bolt::Error.new("Invalid parameter name #{param.inspect}", "bolt/invalid-plan") end definition_keys = definition.keys.to_set unless PARAMETER_KEYS.superset?(definition_keys) invalid_keys = definition_keys - PARAMETER_KEYS raise Bolt::Error.new("Plan parameter #{param.inspect} contains illegal key(s)" \ " #{invalid_keys.to_a.inspect}", "bolt/invalid-plan") end end |