Method: Puppet::Parameter::ValueCollection#newvalue

Defined in:
lib/puppet/parameter/value_collection.rb

#newvalue(name, options = {}, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Option :event original comment says “event should be returned…”, is “returned” the correct word to use?

Defines a new valid value for a Puppet::Property. A valid value is specified as a literal (typically a Symbol), but can also be specified with a regexp.

Parameters:

  • name (Symbol, Regexp)

    a valid literal value, or a regexp that matches a value

  • options (Hash) (defaults to: {})

    a hash with options

Options Hash (options):

  • :event (Symbol)

    The event that should be emitted when this value is set.

  • :invalidate_refreshes (Symbol)

    True if a change on this property should invalidate and remove any scheduled refreshes (from notify or subscribe) targeted at the same resource. For example, if a change in this property takes into account any changes that a scheduled refresh would have performed, then the scheduled refresh would be deleted.

  • _any_ (Object)

    Any other option is treated as a call to a setter having the given option name (e.g. :required_features calls required_features= with the option’s value as an argument).



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/puppet/parameter/value_collection.rb', line 133

def newvalue(name, options = {}, &block)
  call_opt = options[:call]
  unless call_opt.nil?
    devfail "Cannot use obsolete :call value '#{call_opt}' for property '#{self.class.name}'" unless call_opt == :none || call_opt == :instead
    # TRANSLATORS ':call' is a property and should not be translated
    message = _("Property option :call is deprecated and no longer used.")
    message += ' ' + _("Please remove it.")
    Puppet.deprecation_warning(message)
    options = options.reject { |k, _v| k == :call }
  end

  value = Puppet::Parameter::Value.new(name)
  @values[value.name] = value
  if value.regex?
    @regexes << value
  else
    @strings << value
  end

  options.each { |opt, arg| value.send(opt.to_s + "=", arg) }
  if block_given?
    devfail "Cannot use :call value ':none' in combination with a block for property '#{self.class.name}'" if call_opt == :none
    value.block = block
    value.method ||= "set_#{value.name}" unless value.regex?
  elsif call_opt == :instead
    devfail "Cannot use :call value ':instead' without a block for property '#{self.class.name}'"
  end
  value
end