Class: Puppet::Property::KeyValue

Inherits:
Puppet::Property show all
Defined in:
lib/vendor/puppet/property/keyvalue.rb

Constant Summary

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Instance Attribute Summary

Attributes inherited from Puppet::Property

#noop, #shadow, #shouldorig

Attributes inherited from Puppet::Parameter

#parent, #resource

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods inherited from Puppet::Property

array_matching, array_matching=, #call_provider, #call_valuemethod, #change_to_s, #event, #event_name, #initialize, #log, #match_all?, method_added, #munge, #name, newvalue, #property_matches?, #safe_insync?, #set, #setup_shadow, #should=, #sync, #unsafe_validate, #validate_features_per_value, #value, #value=, value_name, value_option

Methods inherited from Puppet::Parameter

aliasvalue, defaultto, desc, #devfail, doc, #fail, format_value_for_display, #initialize, initvars, isnamevar, isnamevar?, isrequired, #log, #metaparam?, #munge, munge, #name, newvalues, nodefault, #noop, #pathbuilder, #provider, proxymethods, #remove, required?, #tags, #to_s, unmunge, #unmunge, #unsafe_munge, #unsafe_validate, validate, #validate, #value, #value=

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, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

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

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #send_log

Methods included from Util::LogPaths

#path, #source_descriptors

Methods included from Util::Errors

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

Constructor Details

This class inherits a constructor from Puppet::Property

Instance Method Details

#delimiterObject



66
67
68
# File 'lib/vendor/puppet/property/keyvalue.rb', line 66

def delimiter
  ";"
end

#hash_to_key_value_s(hash) ⇒ Object



15
16
17
# File 'lib/vendor/puppet/property/keyvalue.rb', line 15

def hash_to_key_value_s(hash)
  hash.select { |k,v| true }.map { |pair| pair.join(separator) }.join(delimiter)
end

#hashify(key_value_array) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/vendor/puppet/property/keyvalue.rb', line 35

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?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/vendor/puppet/property/keyvalue.rb', line 31

def inclusive?
  @resource[membership] == :inclusive
end

#insync?(is) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/vendor/puppet/property/keyvalue.rb', line 79

def insync?(is)
  return true unless is

  (is == self.should)
end

#is_to_s(current_value) ⇒ Object



23
24
25
# File 'lib/vendor/puppet/property/keyvalue.rb', line 23

def is_to_s(current_value)
  hash_to_key_value_s(current_value)
end

#membershipObject



27
28
29
# File 'lib/vendor/puppet/property/keyvalue.rb', line 27

def membership
  :key_value_membership
end

#process_current_hash(current) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/vendor/puppet/property/keyvalue.rb', line 44

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

#retrieveObject



70
71
72
73
74
75
76
77
# File 'lib/vendor/puppet/property/keyvalue.rb', line 70

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

#separatorObject



62
63
64
# File 'lib/vendor/puppet/property/keyvalue.rb', line 62

def separator
  "="
end

#shouldObject



52
53
54
55
56
57
58
59
60
# File 'lib/vendor/puppet/property/keyvalue.rb', line 52

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) ⇒ Object



19
20
21
# File 'lib/vendor/puppet/property/keyvalue.rb', line 19

def should_to_s(should_value)
  hash_to_key_value_s(should_value)
end