class Puppet::Property::KeyValue

This subclass of {Puppet::Property} manages string key value pairs. In order to use this property:

@note *IMPORTANT*: In order for this property to work there must also be a ‘membership’ parameter

The class that inherits from property should override that method with the symbol for the membership

@todo The node with an important message is not very clear.

Public Instance Methods

delimiter() click to toggle source

@return [String] Returns a default delimiter of “;”

# File lib/puppet/property/keyvalue.rb, line 69
def delimiter
  ";"
end
hash_to_key_value_s(hash) click to toggle source
# File lib/puppet/property/keyvalue.rb, line 16
def hash_to_key_value_s(hash)
  hash.select { |k,v| true }.map { |pair| pair.join(separator) }.join(delimiter)
end
hashify(key_value_array) click to toggle source
# File lib/puppet/property/keyvalue.rb, line 36
def hashify(key_value_array)
  #turns string array into a hash
  key_value_array.inject({}) do |hash, key_value|
    tmp = key_value.split(separator)
    hash[tmp[0].intern] = tmp[1]
    hash
  end
end
inclusive?() click to toggle source
# File lib/puppet/property/keyvalue.rb, line 32
def inclusive?
  @resource[membership] == :inclusive
end
insync?(is) click to toggle source

Returns true if there is no is value, else returns if is is equal to should using == as comparison. @return [Boolean] whether the property is in sync or not.

# File lib/puppet/property/keyvalue.rb, line 88
def insync?(is)
  return true unless is

  (is == self.should)
end
is_to_s(current_value) click to toggle source
# File lib/puppet/property/keyvalue.rb, line 24
def is_to_s(current_value)
  hash_to_key_value_s(current_value)
end
membership() click to toggle source
# File lib/puppet/property/keyvalue.rb, line 28
def membership
  :key_value_membership
end
process_current_hash(current) click to toggle source
# File lib/puppet/property/keyvalue.rb, line 45
def process_current_hash(current)
  return {} if current == :absent

  #inclusive means we are managing everything so if it isn't in should, its gone
  current.each_key { |key| current[key] = nil } if inclusive?
  current
end
retrieve() click to toggle source

Retrieves the key-hash from the provider by invoking it’s method named the same as this property. @return [Hash] the hash from the provider, or `:absent`

# File lib/puppet/property/keyvalue.rb, line 76
def retrieve
  #ok, some 'convention' if the keyvalue property is named properties, provider should implement a properties method
  if key_hash = provider.send(name) and key_hash != :absent
    return key_hash
  else
    return :absent
  end
end
separator() click to toggle source

@return [String] Returns a default separator of “=”

# File lib/puppet/property/keyvalue.rb, line 64
def separator
  "="
end
should() click to toggle source
# File lib/puppet/property/keyvalue.rb, line 53
def should
  return nil unless @should

  members = hashify(@should)
  current = process_current_hash(retrieve)

  #shared keys will get overwritten by members
  current.merge(members)
end
should_to_s(should_value) click to toggle source
# File lib/puppet/property/keyvalue.rb, line 20
def should_to_s(should_value)
  hash_to_key_value_s(should_value)
end