Method: Chef::Resource::PlatformMap#set

Defined in:
lib/chef/resource_platform_map.rb

#set(args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/chef/resource_platform_map.rb', line 57

def set(args)
  validate(
    args,
    {
      :platform => {
        :kind_of => Symbol,
        :required => false
      },
      :version => {
        :kind_of => String,
        :required => false
      },
      :short_name => {
        :kind_of => Symbol,
        :required => true
      },
      :resource => {
        :kind_of => [ String, Symbol, Class ],
        :required => true
      }
    }
  )
  if args.has_key?(:platform)
    if args.has_key?(:version)
      if map.has_key?(args[:platform])
        if map[args[:platform]].has_key?(args[:version])
          map[args[:platform]][args[:version]][args[:short_name].to_sym] = args[:resource]
        else
          map[args[:platform]][args[:version]] = {
            args[:short_name].to_sym => args[:resource]
          }
        end
      else
        map[args[:platform]] = {
          args[:version] => {
            args[:short_name].to_sym => args[:resource]
          }
        }
      end
    else
      if map.has_key?(args[:platform])
        if map[args[:platform]].has_key?(:default)
          map[args[:platform]][:default][args[:short_name].to_sym] = args[:resource]
        else
          map[args[:platform]] = { :default => { args[:short_name].to_sym => args[:resource] } }
        end
      else
        map[args[:platform]] = {
          :default => {
            args[:short_name].to_sym => args[:resource]
          }
        }
      end
    end
  else
    if map.has_key?(:default)
      map[:default][args[:short_name].to_sym] = args[:resource]
    else
      map[:default] = {
        args[:short_name].to_sym => args[:resource]
      }
    end
  end
end