Class: Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/dsl/platform_introspection.rb

Overview

Implementation class for determining platform family dependent values

Instance Method Summary collapse

Constructor Details

#initialize(platform_family_hash) ⇒ PlatformFamilyDependentValue

Create a platform family dependent value object.

Arguments

platform_family_hash (Hash) a map of platform families to values. like this:

{
  :rhel => "value for all EL variants"
  :fedora =>  "value for fedora variants fedora and amazon" ,
  [:fedora, :rhel] => "value for all known redhat variants"
  :debian =>  "value for debian variants including debian, ubuntu, mint" ,
  :default => "the default when nothing else matches"
}
  • platform families can be specified as Symbols or Strings

  • multiple platform families can be grouped by using an Array as the key

  • values for platform families can be any object, with no restrictions. Some examples:

    • :stop, :start
    • “mysql-devel”

    • { :key => “value” }



151
152
153
154
155
# File 'lib/chef/dsl/platform_introspection.rb', line 151

def initialize(platform_family_hash)
  @values = {}
  @values["default"] = nil
  platform_family_hash.each { |platform_families, value| set(platform_families, value)}
end

Instance Method Details

#value_for_node(node) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/chef/dsl/platform_introspection.rb', line 157

def value_for_node(node)
  if node.key?(:platform_family)
    platform_family = node[:platform_family].to_s
    if @values.key?(platform_family)
      @values[platform_family]
    else
      @values["default"]
    end
  else
    @values["default"]
  end
end