class Puppet::Parameter::Value
Describes an acceptable value for a parameter or property. An acceptable value is either specified as a literal value or a regular expression. @note this class should be used via the api methods in {Puppet::Parameter} and {Puppet::Property} @api private
Attributes
Public Class Methods
Initializes the instance with a literal accepted value, or a regular expression. If anything else is passed, it is turned into a String, and then made into a Symbol. @param name [Symbol, Regexp, Object] the value to accept, Symbol, a regular expression, or object to convert. @api private
# File lib/puppet/parameter/value.rb 40 def initialize(name) 41 if name.is_a?(Regexp) 42 @name = name 43 else 44 # Convert to a string and then a symbol, so things like true/false 45 # still show up as symbols. 46 @name = convert(name) 47 end 48 49 @aliases = [] 50 end
Public Instance Methods
Adds an alias for this value. Makes the given name be an alias for this acceptable value. @param name [Symbol] the additional alias this value should be known as @api private
# File lib/puppet/parameter/value.rb 17 def alias(name) 18 @aliases << convert(name) 19 end
@return [Array<Symbol>] Returns all aliases (or an empty array). @api private
# File lib/puppet/parameter/value.rb 24 def aliases 25 @aliases.dup 26 end
Stores the event that our value generates, if it does so. @api private
# File lib/puppet/parameter/value.rb 31 def event=(value) 32 @event = convert(value) 33 end
Checks if the given value matches the acceptance rules (literal value, regular expression, or one of the aliases. @api private
# File lib/puppet/parameter/value.rb 56 def match?(value) 57 if regex? 58 return true if name =~ value.to_s 59 else 60 return(name == convert(value) ? true : @aliases.include?(convert(value))) 61 end 62 end
@return [Boolean] whether the accepted value is a regular expression or not. @api private
# File lib/puppet/parameter/value.rb 67 def regex? 68 @name.is_a?(Regexp) 69 end
Private Instance Methods
A standard way of converting all of our values, so we're always comparing apples to apples. @api private
# File lib/puppet/parameter/value.rb 77 def convert(value) 78 case value 79 when Symbol, '' # can't intern an empty string 80 value 81 when String 82 value.intern 83 when true 84 :true 85 when false 86 :false 87 else 88 value.to_s.intern 89 end 90 end