~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to lib/puppet/provider/confine_collection.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Manage a collection of confines, returning a boolean or
 
2
# helpful information.
 
3
require 'puppet/provider/confine'
 
4
 
 
5
class Puppet::Provider::ConfineCollection
 
6
    def confine(hash)
 
7
        if hash.include?(:for_binary)
 
8
            for_binary = true
 
9
            hash.delete(:for_binary)
 
10
        else
 
11
            for_binary = false
 
12
        end
 
13
        hash.each do |test, values|
 
14
            if klass = Puppet::Provider::Confine.test(test)
 
15
                @confines << klass.new(values)
 
16
                @confines[-1].for_binary = true if for_binary
 
17
            else
 
18
                confine = Puppet::Provider::Confine.test(:variable).new(values)
 
19
                confine.name = test
 
20
                @confines << confine
 
21
            end
 
22
        end
 
23
    end
 
24
 
 
25
    def initialize
 
26
        @confines = []
 
27
    end
 
28
 
 
29
    # Return a hash of the whole confine set, used for the Provider
 
30
    # reference.
 
31
    def summary
 
32
        confines = Hash.new { |hash, key| hash[key] = [] }
 
33
        @confines.each { |confine| confines[confine.class] << confine }
 
34
        result = {}
 
35
        confines.each do |klass, list|
 
36
            value = klass.summarize(list)
 
37
            next if (value.respond_to?(:length) and value.length == 0) or (value == 0)
 
38
            result[klass.name] = value
 
39
 
 
40
        end
 
41
        result
 
42
    end
 
43
 
 
44
    def valid?
 
45
        ! @confines.detect { |c| ! c.valid? }
 
46
    end
 
47
end