summaryrefslogtreecommitdiff
path: root/lib/chef/node_filter.rb
blob: 7df59b572b52fb8f39e632db0453882d0d38489b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Chef
  class NodeMapValue
    def initialize(&filter)
    end

    def <=>(other)
      priority <=> other.priority
    end
    def priority
      Float::INFINITY
    end
    def value
      filter.call(run_context)
    end
  end

  class FilteredValue
    def initialize(name, os: nil, platform: nil, platform_family: nil, &filter)
      @name = name
      @os = os
      @platform = platform
      @platform_family = platform_family
      super(&filter)
    end

    def <=>(other)
      if other.is_a?(FilteredValue)
        if platform_family != other.platform_family
          return platform_family ? -1 : 1
        end
        if platform != other.platform
          return platform ? -1 : 1
        end
        if os != other.os
          return os ? -1 : 1
        end
      end
    end
  end
end