# class Chef::Resource::PlatformMap

### Attributes

map[R]

### Public Class Methods

new(map={:default => {}}) click to toggle source

    # File lib/chef/resource_platform_map.rb, line 31
    def initialize(map={:default => {}})
      @map = map
    end

### Public Instance Methods

filter(platform, version) click to toggle source

    # File lib/chef/resource_platform_map.rb, line 35
    def filter(platform, version)
      resource_map = map[:default].clone
      platform_sym = platform
      if platform.kind_of?(String)
        platform.downcase!
        platform.gsub!(/\s/, "_")
        platform_sym = platform.to_sym
      end

      if map.has_key?(platform_sym)
        if map[platform_sym].has_key?(version)
          if map[platform_sym].has_key?(:default)
            resource_map.merge!(map[platform_sym][:default])
          end
          resource_map.merge!(map[platform_sym][version])
        elsif map[platform_sym].has_key?(:default)
          resource_map.merge!(map[platform_sym][:default])
        end
      end
      resource_map
    end

get(short_name, platform=nil, version=nil) click to toggle source

    # File lib/chef/resource_platform_map.rb, line 122
    def get(short_name, platform=nil, version=nil)
      resource_klass = platform_resource(short_name, platform, version) ||
                       resource_matching_short_name(short_name)

      raise Exceptions::NoSuchResourceType, "Cannot find a resource for #{short_name} on #{platform} version #{version}" if resource_klass.nil?

      resource_klass
    end

set(args) click to toggle source

    # 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