summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/confine_collection.rb
blob: 0dbdc77907a12d519c50283575a1cc6aaa457e93 (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
41
42
43
44
45
46
47
48
49
50
# Manage a collection of confines, returning a boolean or
# helpful information.
require 'puppet/provider/confine'

class Puppet::Provider::ConfineCollection
    def confine(hash)
        if hash.include?(:for_binary)
            for_binary = true
            hash.delete(:for_binary)
        else
            for_binary = false
        end
        hash.each do |test, values|
            if klass = Puppet::Provider::Confine.test(test)
                @confines << klass.new(values)
                @confines[-1].for_binary = true if for_binary
            else
                confine = Puppet::Provider::Confine.test(:variable).new(values)
                confine.name = test
                @confines << confine
            end
            @confines[-1].label = self.label
        end
    end

    attr_reader :label
    def initialize(label)
        @label = label
        @confines = []
    end

    # Return a hash of the whole confine set, used for the Provider
    # reference.
    def summary
        confines = Hash.new { |hash, key| hash[key] = [] }
        @confines.each { |confine| confines[confine.class] << confine }
        result = {}
        confines.each do |klass, list|
            value = klass.summarize(list)
            next if (value.respond_to?(:length) and value.length == 0) or (value == 0)
            result[klass.name] = value

        end
        result
    end

    def valid?
        ! @confines.detect { |c| ! c.valid? }
    end
end