Method: Puppet::Provider::DscBaseProvider#enum_values
- Defined in:
- lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
#enum_values(context, attribute) ⇒ Array
Parses the DSC resource type definition to retrieve the values of any attributes which are specified as enums
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb', line 713 def enum_values(context, attribute) # Get the attribute's type string for the given key type_string = context.type.attributes[attribute][:type] # Return an empty array if the key doesn't have an Enum type or doesn't exist return [] unless type_string&.include?('Enum[') # Extract the enum values from the type string enum_content = type_string.match(/Enum\[(.*?)\]/)&.[](1) # Return an empty array if we couldn't find the enum values return [] if enum_content.nil? # Return an array of the enum values, stripped of extra whitespace and quote marks enum_content.split(',').map { |val| val.strip.delete('\'') } end |