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

block[RW]
event[R]
invalidate_refreshes[RW]
method[RW]
name[R]
options[R]
required_features[RW]

Public Class Methods

new(name) click to toggle source

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
41 def initialize(name)
42   if name.is_a?(Regexp)
43     @name = name
44   else
45     # Convert to a string and then a symbol, so things like true/false
46     # still show up as symbols.
47     @name = convert(name)
48   end
49 
50   @aliases = []
51 end

Public Instance Methods

alias(name) click to toggle source

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
18 def alias(name)
19   @aliases << convert(name)
20 end
aliases() click to toggle source

@return [Array<Symbol>] Returns all aliases (or an empty array). @api private

   # File lib/puppet/parameter/value.rb
25 def aliases
26   @aliases.dup
27 end
event=(value) click to toggle source

Stores the event that our value generates, if it does so. @api private

   # File lib/puppet/parameter/value.rb
32 def event=(value)
33   @event = convert(value)
34 end
match?(value) click to toggle source

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
57 def match?(value)
58   if regex?
59     return true if name =~ value.to_s
60   else
61     return(name == convert(value) ? true : @aliases.include?(convert(value)))
62   end
63 end
regex?() click to toggle source

@return [Boolean] whether the accepted value is a regular expression or not. @api private

   # File lib/puppet/parameter/value.rb
68 def regex?
69   @name.is_a?(Regexp)
70 end

Private Instance Methods

convert(value) click to toggle source

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
78 def convert(value)
79   case value
80   when Symbol, ''             # can't intern an empty string
81     value
82   when String
83     value.intern
84   when true
85     :true
86   when false
87     :false
88   else
89     value.to_s.intern
90   end
91 end