Method: Puppet::Property.newvalue

Defined in:
lib/puppet/property.rb

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

TODO:

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

Defines a new valid value for this 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)

    Indicates 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).



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/puppet/property.rb', line 165

def self.newvalue(name, options = {}, &block)
  value = value_collection.newvalue(name, options, &block)

  unless value.method.nil?
    method = value.method.to_sym
    if value.block
      if instance_methods(false).include?(method)
        raise ArgumentError, _("Attempt to redefine method %{method} with block") % { method: method }
      end

      define_method(method, &value.block)
    else
      # Let the method be an alias for calling the providers setter unless we already have this method
      alias_method(method, :call_provider) unless method_defined?(method)
    end
  end
  value
end