Class: Puppet::Property Abstract

Inherits:
Parameter show all
Defined in:
lib/puppet/property.rb,
lib/puppet/type/zpool.rb,
lib/puppet/property/list.rb,
lib/puppet/property/keyvalue.rb,
lib/puppet/property/ordered_list.rb

Overview

This class is abstract.
TODO:

Describe meta-parameter shadowing. This concept can not be understood by just looking at the descriptions of the methods involved.

Note:

Properties of Types are expressed using subclasses of this class. Such a class describes one named property of a particular Type (as opposed to describing a type of property in general). This limits the use of one (concrete) property class instance to occur only once for a given type’s inheritance chain. An instance of a Property class is the value holder of one instance of the resource type (e.g. the mode of a file resource instance). A Property class may server as the superclass _(parent)_ of another; e.g. a Size property that describes handling of measurements such as kb, mb, gb. If a type requires two different size measurements it requires one concrete class per such measure; e.g. MinSize (:parent => Size), and MaxSize (:parent => Size).

The Property class is the implementation of a resource’s attributes of property kind. A Property is a specialized Resource Type Parameter that has both an ‘is’ (current) state, and a ‘should’ (wanted state). However, even if this is conceptually true, the current is value is obtained by asking the associated provider for the value, and hence it is not actually part of a property’s state, and only available when a provider has been selected and can obtain the value (i.e. when running on an agent).

A Property (also in contrast to a parameter) is intended to describe a managed attribute of some system entity, such as the name or mode of a file.

The current value _(is)_ is read and written with the methods #retrieve and #set, and the wanted value _(should)_ is read and written with the methods #value and #value= which delegate to #should and #should=, i.e. when a property is used like any other parameter, it is the should value that is operated on.

All resource type properties in the puppet system are derived from this class.

The intention is that new parameters are created by using the DSL method Type.newproperty.

See Also:

Direct Known Subclasses

Boolean, Ensure, KeyValue, List, VDev, SELFileContext

Defined Under Namespace

Classes: Boolean, Ensure, KeyValue, List, MultiVDev, OrderedList, VDev

Constant Summary

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Parameter

#parent, #resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parameter

aliasvalue, defaultto, desc, doc, #file, format_value_for_display, initvars, isnamevar, isnamevar?, #isnamevar?, isrequired, #line, #metaparam?, munge, newvalues, nodefault, #path, #pathbuilder, #provider, proxymethods, #remove, required?, #required?, #tags, #to_s, #unmunge, unmunge, #unsafe_munge, validate, #validate, #version

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, symbolizehash, thinmark, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

#initialize(hash = {}) ⇒ Property

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:

There is some special initialization when a property is not a metaparameter but Puppet::Type.metaparamclass(for this class’s name) is not nil - if that is the case a setup_shadow is performed for that class.

Note:

New properties of a type should be created via the DSL method Type.newproperty.

Initializes a Property the same way as a Parameter and handles the special case when a property is shadowing a meta-parameter.

Parameters:

See Also:



293
294
295
296
297
298
299
# File 'lib/puppet/property.rb', line 293

def initialize(hash = {})
  super

  if ! self.metaparam? and klass = Puppet::Type.metaparamclass(self.class.name)
    setup_shadow(klass)
  end
end

Class Attribute Details

.array_matchingSymbol

Note:

The semantics of these modes are implemented by the method #insync?. That method is the default implementation and it has a backwards compatible behavior that imposes additional constraints on what constitutes a positive match. A derived property may override that method.

The ‘is` vs. `should` array matching mode; `:first`, or `:all`.

  • ‘:first` This is primarily used for single value properties. When matched against an array of values a match is true if the `is` value matches any of the values in the `should` array. When the `is` value is also an array, the matching is performed against the entire array as the `is` value.

  • ‘:all` : This is primarily used for multi-valued properties. When matched against an array of

    `should` values, the size of `is` and `should` must be the same, and all values in `is` must match
    a value in `should`.
    

Returns:

  • (Symbol)

    (:first) the mode in which matching is performed

See Also:



93
94
95
# File 'lib/puppet/property.rb', line 93

def array_matching
  @array_matching ||= :first
end

.nameSymbol (readonly)

Returns The name of the property as given when the property was created.

Returns:

  • (Symbol)

    The name of the property as given when the property was created.



69
70
71
# File 'lib/puppet/property.rb', line 69

def name
  @name
end

.unmanagedObject

TODO:

Figure out what this is used for. Can not find any logic in the puppet code base that reads or writes this attribute.

??? Probably Unused



65
66
67
# File 'lib/puppet/property.rb', line 65

def unmanaged
  @unmanaged
end

Instance Attribute Details

#noopBoolean

TODO:

This logic is different than Parameter#noop in that the resource noop mode overrides the property’s mode - in parameter it is the other way around. Bug or feature?

Returns whether this property is in noop mode or not; if a difference between the is and should values should be acted on or not. The noop mode is a transitive setting. The mode is checked in this property, then in the _associated resource_ and finally in Puppet.

Returns:

  • (Boolean)

    whether this property is in noop mode or not.



451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/puppet/property.rb', line 451

def noop
  # This is only here to make testing easier.
  if @resource.respond_to?(:noop?)
    @resource.noop?
  else
    if defined?(@noop)
      @noop
    else
      Puppet[:noop]
    end
  end
end

#shadowObject (readonly)

TODO:

What is this?

What is this used for?



282
283
284
# File 'lib/puppet/property.rb', line 282

def shadow
  @shadow
end

#shouldorigArray<Object>, ... (readonly)

Returns the original wanted value(s) _(should)_ unprocessed by munging/unmunging. The original values are set by #value= or #should=.

Returns:



51
52
53
# File 'lib/puppet/property.rb', line 51

def shouldorig
  @shouldorig
end

Class Method Details

.method_added(sym) ⇒ 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.

Protects against override of the #safe_insync? method.

Raises:

  • (RuntimeError)

    if the added method is ‘:safe_insync?`



321
322
323
# File 'lib/puppet/property.rb', line 321

def self.method_added(sym)
  raise "Puppet::Property#safe_insync? shouldn't be overridden; please override insync? instead" if sym == :safe_insync?
end

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

TODO:

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

TODO:

The original documentation states that the option ‘:method` will set the name of the generated setter method, but this is not implemented. Is the documentatin or the implementation in error? (The implementation is in Puppet::Parameter::ValueCollection#new_value).

TODO:

verify that the use of :before and :after have been deprecated (or rather - never worked, and was never in use. (This means, that the option :call could be removed since calls are always :instead).

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.

  • :call (Symbol)

    When to call any associated block. The default value is ‘:instead` which means that the block should be called instead of the provider. In earlier versions (before 20081031) it was possible to specify a value of `:before` or `:after` for the purpose of calling both the block and the provider. Use of these deprecated options will now raise an exception later in the process when the is value is set (see #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).



160
161
162
163
164
165
# File 'lib/puppet/property.rb', line 160

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

  define_method(value.method, &value.block) if value.method and value.block
  value
end

.value_name(name) ⇒ Symbol, Regexp

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.

Looks up a value’s name among valid values, to enable option lookup with result as a key.

Parameters:

  • name (Object)

    the parameter value to match against valid values (names).

Returns:



111
112
113
114
115
# File 'lib/puppet/property.rb', line 111

def self.value_name(name)
  if value = value_collection.match?(name)
    value.name
  end
end

.value_option(name, option) ⇒ 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:

Guessing on result of passing a non supported option (it performs send(option)).

Returns the value of the given option (set when a valid value with the given “name” was defined).

Parameters:

Returns:

  • (Object)

    value of the option

Raises:

  • (NoMethodError)

    if the option is not supported



125
126
127
128
129
# File 'lib/puppet/property.rb', line 125

def self.value_option(name, option)
  if value = value_collection.value(name)
    value.send(option)
  end
end

Instance Method Details

#call_provider(value) ⇒ 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.

Calls the provider setter method for this property with the given value as argument.

Returns:

  • (Object)

    what the provider returns when calling a setter for this property’s name

Raises:

  • (Puppet::Error)

    when the provider can not handle this property.

See Also:



173
174
175
176
177
178
179
# File 'lib/puppet/property.rb', line 173

def call_provider(value)
    method = self.class.name.to_s + "="
    unless provider.respond_to? method
      self.fail "The #{provider.class.name} provider can not handle attribute #{self.class.name}"
    end
    provider.send(method, value)
end

#call_valuemethod(name, value) ⇒ 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:

The check for a valid value option called ‘:method` does not seem to be fully supported as it seems that this option is never consulted when the method is dynamically created. Needs to be investigated. (Bug, or documentation needs to be changed).

Sets the value of this property to the given value by calling the dynamically created setter method associated with the “valid value” referenced by the given name.

Parameters:

  • name (Symbol, Regexp)

    a valid value “name” as returned by value_name

  • value (Object)

    the value to set as the value of the property

Raises:

  • (Puppet::DevError)

    if there was no method to call

  • (Puppet::Error)

    if there were problems setting the value

  • (Puppet::ResourceError)

    if there was a problem setting the value and it was not raised as a Puppet::Error. The original exception is wrapped and logged.

See Also:



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/puppet/property.rb', line 194

def call_valuemethod(name, value)
  if method = self.class.value_option(name, :method) and self.respond_to?(method)
    begin
      self.send(method)
    rescue Puppet::Error
      raise
    rescue => detail
      error = Puppet::ResourceError.new("Could not set '#{value}' on #{self.class.name}: #{detail}", @resource.line, @resource.file, detail)
      error.set_backtrace detail.backtrace
      Puppet.log_exception(detail, error.message)
      raise error
    end
  elsif block = self.class.value_option(name, :block)
    # FIXME It'd be better here to define a method, so that
    # the blocks could return values.
    self.instance_eval(&block)
  else
    devfail "Could not find method for value '#{name}'"
  end
end

#change_to_s(current_value, newvalue) ⇒ String

Note:

If called with equal values, this is reported as a change.

Formats a message for a property change from the given ‘current_value` to the given `newvalue`.

Returns:

  • (String)

    a message describing the property change.

Raises:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/puppet/property.rb', line 220

def change_to_s(current_value, newvalue)
  begin
    if current_value == :absent
      return "defined '#{name}' as #{self.class.format_value_for_display should_to_s(newvalue)}"
    elsif newvalue == :absent or newvalue == [:absent]
      return "undefined '#{name}' from #{self.class.format_value_for_display is_to_s(current_value)}"
    else
      return "#{name} changed #{self.class.format_value_for_display is_to_s(current_value)} to #{self.class.format_value_for_display should_to_s(newvalue)}"
    end
  rescue Puppet::Error, Puppet::DevError
    raise
  rescue => detail
    message = "Could not convert change '#{name}' to string: #{detail}"
    Puppet.log_exception(detail, message)
    raise Puppet::DevError, message, detail.backtrace
  end
end

#eventPuppet::Transaction::Event

TODO:

What is the intent of this method? What is the meaning of the :source_description passed in the options to the created event?

Produces an event describing a change of this property. In addition to the event attributes set by the resource type, this method adds:

  • ‘:name` - the event_name

  • ‘:desired_value` - a.k.a should or _wanted value_

  • ‘:property` - reference to this property

  • ‘:source_description` - the path (?? See todo)

  • ‘:invalidate_refreshes` - if scheduled refreshes should be invalidated

Returns:

See Also:



272
273
274
275
276
277
278
# File 'lib/puppet/property.rb', line 272

def event
  attrs = { :name => event_name, :desired_value => should, :property => self, :source_description => path }
  if should and value = self.class.value_collection.match?(should)
    attrs[:invalidate_refreshes] = true if value.invalidate_refreshes
  end
  resource.event attrs
end

#event_nameString

Produces the name of the event to use to describe a change of this property’s value. The produced event name is either the event name configured for this property, or a generic event based on the name of the property with suffix ‘_changed`, or if the property is `:ensure`, the name of the resource type and one of the suffixes `_created`, `_removed`, or `_changed`.

Returns:

  • (String)

    the name of the event that describes the change



244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/puppet/property.rb', line 244

def event_name
  value = self.should

  event_name = self.class.value_option(value, :event) and return event_name

  name == :ensure or return (name.to_s + "_changed").to_sym

  return (resource.type.to_s + case value
  when :present; "_created"
  when :absent; "_removed"
  else
    "_changed"
  end).to_sym
end

#insync?(is) ⇒ Boolean

TODO:

The implementation should really do return is.zip(@should).all? {|a, b| property_matches?(a, b) } instead of using equality check and then check against an array with converted strings.

Note:

The array matching logic in this method contains backwards compatible logic that performs the comparison in ‘:all` mode by checking equality and equality of is against should converted to array of String, and that the lengths are equal, and in `:first` mode by checking if one of the should values is included in the is values. This means that the is value needs to be carefully arranged to match the should.

Checks if the current _(is)_ value is in sync with the wanted _(should)_ value. The check if the two values are in sync is controlled by the result of #match_all? which specifies a match of ‘:first` or `:all`). The matching of the is value against the entire should value or each of the should values (as controlled by #match_all? is performed by #property_matches?.

A derived property typically only needs to override the #property_matches? method, but may also override this method if there is a need to have more control over the array matching logic.

Parameters:

  • is (Object)

    The current _(is)_ value to check if it is in sync with the wanted _(should)_ value(s)

Returns:

  • (Boolean)

    whether the values are in sync or not.

Raises:



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/puppet/property.rb', line 345

def insync?(is)
  self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array)

  # an empty array is analogous to no should values
  return true if @should.empty?

  # Look for a matching value, either for all the @should values, or any of
  # them, depending on the configuration of this property.
  if match_all? then
    # Emulate Array#== using our own comparison function.
    # A non-array was not equal to an array, which @should always is.
    return false unless is.is_a? Array

    # If they were different lengths, they are not equal.
    return false unless is.length == @should.length

    # Finally, are all the elements equal?  In order to preserve the
    # behaviour of previous 2.7.x releases, we need to impose some fun rules
    # on "equality" here.
    #
    # Specifically, we need to implement *this* comparison: the two arrays
    # are identical if the is values are == the should values, or if the is
    # values are == the should values, stringified.
    #
    # This does mean that property equality is not commutative, and will not
    # work unless the `is` value is carefully arranged to match the should.
    return (is == @should or is == @should.map(&:to_s))

    # When we stop being idiots about this, and actually have meaningful
    # semantics, this version is the thing we actually want to do.
    #
    # return is.zip(@should).all? {|a, b| property_matches?(a, b) }
  else
    return @should.any? {|want| property_matches?(is, want) }
  end
end

#is_to_s(currentvalue) ⇒ String

Produces a pretty printing string for the given value. This default implementation simply returns the given argument. A derived implementation may perform property specific pretty printing when the is and should values are not already in suitable form.

Returns:

  • (String)

    a pretty printing string



404
405
406
# File 'lib/puppet/property.rb', line 404

def is_to_s(currentvalue)
  currentvalue
end

#log(msg) ⇒ void

This method returns an undefined value.

Emits a log message at the log level specified for the associated resource. The log entry is associated with this property.

Parameters:

  • msg (String)

    the message to log



413
414
415
416
417
418
419
# File 'lib/puppet/property.rb', line 413

def log(msg)
  Puppet::Util::Log.create(
    :level   => resource[:loglevel],
    :message => msg,
    :source  => self
  )
end

#match_all?Boolean

Returns whether the array_matching mode is set to ‘:all` or not.

Returns:



422
423
424
# File 'lib/puppet/property.rb', line 422

def match_all?
  self.class.array_matching == :all
end

#munge(value) ⇒ Object

TODO:

Incomprehensible ! The concept of “meta-parameter-shadowing” needs to be explained.

Note:

This method should not be overridden. Use the DSL method #munge to define a munging method if required.

Munges the value to internal form. This implementation of ‘munge` provides exception handling around the specified munging of this parameter. If this property is a meta-parameter shadow, the shadow’s munge is also called.

Parameters:

  • value (Object)

    the DSL value to munge

Returns:

  • (Object)

    the munged (internal) value



430
431
432
433
434
# File 'lib/puppet/property.rb', line 430

def munge(value)
  self.shadow.munge(value) if self.shadow

  super
end

#nameSymbol

Note:

A property class (just like a parameter class) describes one specific property and can only be used once within one type’s inheritance chain.

Returns the name of the property as stated when the property was created.

Returns:

  • (Symbol)

    the name of the property as stated when the property was created.



439
440
441
# File 'lib/puppet/property.rb', line 439

def name
  self.class.name
end

#property_matches?(current, desired) ⇒ Boolean

Checks if the given current and desired values are equal. This default implementation performs this check in a backwards compatible way where the equality of the two values is checked, and then the equality of current with desired converted to a string.

A derived implementation may override this method to perform a property specific equality check.

The intent of this method is to provide an equality check suitable for checking if the property value is in sync or not. It is typically called from #insync?.

Returns:



392
393
394
395
396
397
# File 'lib/puppet/property.rb', line 392

def property_matches?(current, desired)
  # This preserves the older Puppet behaviour of doing raw and string
  # equality comparisons for all equality.  I am not clear this is globally
  # desirable, but at least it is not a breaking change. --daniel 2011-11-11
  current == desired or current == desired.to_s
end

#retrieveObject

Retrieves the current value _(is)_ of this property from the provider. This implementation performs this operation by calling a provider method with the same name as this property (i.e. if the property name is ‘gid’, a call to the ‘provider.gid’ is expected to return the current value.

Returns:

  • (Object)

    what the provider returns as the current value of the property



470
471
472
# File 'lib/puppet/property.rb', line 470

def retrieve
  provider.send(self.class.name)
end

#safe_insync?(is) ⇒ Boolean

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.

Note:

If the wanted value _(should)_ is not defined or is set to a non-true value then this is a state that can not be fixed and the property is reported to be in sync.

Note:

Do not override this method.

Determines whether the property is in-sync or not in a way that is protected against missing value.

Returns:

  • (Boolean)

    the protected result of ‘true` or the result of calling #insync?.



309
310
311
312
313
314
315
# File 'lib/puppet/property.rb', line 309

def safe_insync?(is)
  # If there is no @should value, consider the property to be in sync.
  return true unless @should

  # Otherwise delegate to the (possibly derived) insync? method.
  insync?(is)
end

#set(value) ⇒ Object

Note:

In older versions (before 20081031) it was possible to specify the call types ‘:before` and `:after` which had the effect that both the provider method and the _valid value_ block were called. This is no longer supported.

Sets the current _(is)_ value of this property. The value is set using the provider’s setter method for this property (#call_provider) if nothing else has been specified. If the _valid value_ for the given value defines a ‘:call` option with the value `:instead`, the value is set with #call_valuemethod which invokes a block specified for the valid value.

Parameters:

  • value (Object)

    the value to set as the value of this property

Returns:

Raises:

  • (Puppet::Error)

    when the provider setter should be used but there is no provider set in the _associated resource_

  • (Puppet::DevError)

    when a deprecated call form was specified (e.g. ‘:before` or `:after`).



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/puppet/property.rb', line 491

def set(value)
  # Set a name for looking up associated options like the event.
  name = self.class.value_name(value)

  call = self.class.value_option(name, :call) || :none

  if call == :instead
    call_valuemethod(name, value)
  elsif call == :none
    # They haven't provided a block, and our parent does not have
    # a provider, so we have no idea how to handle this.
    self.fail "#{self.class.name} cannot handle values of type #{value.inspect}" unless @resource.provider
    call_provider(value)
  else
    # LAK:NOTE 20081031 This is a change in behaviour -- you could
    # previously specify :call => [;before|:after], which would call
    # the setter *in addition to* the block.  I'm convinced this
    # was never used, and it makes things unecessarily complicated.
    # If you want to specify a block and still call the setter, then
    # do so in the block.
    devfail "Cannot use obsolete :call value '#{call}' for property '#{self.class.name}'"
  end
end

#setup_shadow(klass) ⇒ Puppet::Parameter

Sets up a shadow property for a shadowing meta-parameter. This construct allows the creation of a property with the same name as a meta-parameter. The metaparam will only be stored as a shadow.

Parameters:

Returns:



521
522
523
# File 'lib/puppet/property.rb', line 521

def setup_shadow(klass)
  @shadow = klass.new(:resource => self.resource)
end

#shouldArray<Object>, ...

Note:

This method will potentially return different values than the original values as they are converted via munging/unmunging. If the original values are wanted, call #shouldorig.

Returns the wanted _(should)_ value of this property. If the _array matching mode_ #match_all? is true, an array of the wanted values in unmunged format is returned, else the first value in the array of wanted values in unmunged format is returned.

Returns:

Raises:

See Also:



538
539
540
541
542
543
544
545
546
547
548
# File 'lib/puppet/property.rb', line 538

def should
  return nil unless defined?(@should)

  self.devfail "should for #{self.class.name} on #{resource.name} is not an array" unless @should.is_a?(Array)

  if match_all?
    return @should.collect { |val| self.unmunge(val) }
  else
    return self.unmunge(@should[0])
  end
end

#should=(values) ⇒ Object

Sets the wanted _(should)_ value of this property. If the given value is not already an Array, it will be wrapped in one before being set. This method also sets the cached original should values returned by #shouldorig.

Parameters:

Raises:



558
559
560
561
562
563
564
565
# File 'lib/puppet/property.rb', line 558

def should=(values)
  values = [values] unless values.is_a?(Array)

  @shouldorig = values

  values.each { |val| validate(val) }
  @should = values.collect { |val| self.munge(val) }
end

#should_to_s(newvalue) ⇒ String

Formats the given newvalue (following should type conventions) for inclusion in a string describing a change.

Returns:

  • (String)

    Returns the given newvalue in string form with space separated entries if it is an array.

See Also:



571
572
573
# File 'lib/puppet/property.rb', line 571

def should_to_s(newvalue)
  [newvalue].flatten.join(" ")
end

#syncObject

TODO:

The implementation of this method is somewhat inefficient as it computes the should array twice.

Synchronizes the current value _(is)_ and the wanted value _(should)_ by calling #set.

Raises:



579
580
581
582
# File 'lib/puppet/property.rb', line 579

def sync
  devfail "Got a nil value for should" unless should
  set(should)
end

#unsafe_validate(value) ⇒ void

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.

This method returns an undefined value.

Asserts that the given value is valid. If the developer uses a ‘validate’ hook, this method will get overridden.

Raises:

  • (Exception)

    if the value is invalid, or value can not be handled.



590
591
592
593
# File 'lib/puppet/property.rb', line 590

def unsafe_validate(value)
  super
  validate_features_per_value(value)
end

#validate_features_per_value(value) ⇒ void

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.

This method returns an undefined value.

Asserts that all required provider features are present for the given property value.

Raises:

  • (ArgumentError)

    if a required feature is not present



600
601
602
603
604
605
606
# File 'lib/puppet/property.rb', line 600

def validate_features_per_value(value)
  if features = self.class.value_option(self.class.value_name(value), :required_features)
    features = Array(features)
    needed_features = features.collect { |f| f.to_s }.join(", ")
    raise ArgumentError, "Provider must have features '#{needed_features}' to set '#{self.class.name}' to '#{value}'" unless provider.satisfies?(features)
  end
end

#valueObject?

Returns the wanted _(should)_ value of this property.

Returns:

  • (Object, nil)

    Returns the wanted _(should)_ value of this property.



609
610
611
# File 'lib/puppet/property.rb', line 609

def value
  self.should
end

#value=(values) ⇒ Object

Sets the wanted _(should)_ value of this property. If the given value is not already an Array, it will be wrapped in one before being set. This method also sets the cached original should values returned by #shouldorig.

Parameters:

Raises:



614
615
616
# File 'lib/puppet/property.rb', line 614

def value=(values)
  self.should = values
end