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

« back to all changes in this revision

Viewing changes to lib/puppet/indirector.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Manage indirections to termini.  They are organized in terms of indirections -
 
2
# - e.g., configuration, node, file, certificate -- and each indirection has one
 
3
# or more terminus types defined.  The indirection is configured via the
 
4
# +indirects+ method, which will be called by the class extending itself
 
5
# with this module.
 
6
module Puppet::Indirector
 
7
    # LAK:FIXME We need to figure out how to handle documentation for the
 
8
    # different indirection types.
 
9
 
 
10
    require 'puppet/indirector/indirection'
 
11
    require 'puppet/indirector/terminus'
 
12
    require 'puppet/indirector/envelope'
 
13
 
 
14
    # Declare that the including class indirects its methods to
 
15
    # this terminus.  The terminus name must be the name of a Puppet
 
16
    # default, not the value -- if it's the value, then it gets
 
17
    # evaluated at parse time, which is before the user has had a chance
 
18
    # to override it.
 
19
    def indirects(indirection, options = {})
 
20
        raise(ArgumentError, "Already handling indirection for %s; cannot also handle %s" % [@indirection.name, indirection]) if defined?(@indirection) and @indirection
 
21
        # populate this class with the various new methods
 
22
        extend ClassMethods
 
23
        include InstanceMethods
 
24
        include Puppet::Indirector::Envelope
 
25
 
 
26
        # instantiate the actual Terminus for that type and this name (:ldap, w/ args :node)
 
27
        # & hook the instantiated Terminus into this class (Node: @indirection = terminus)
 
28
        @indirection = Puppet::Indirector::Indirection.new(self, indirection,  options)
 
29
        @indirection
 
30
    end
 
31
 
 
32
    module ClassMethods   
 
33
        attr_reader :indirection
 
34
 
 
35
        def cache_class=(klass)
 
36
            indirection.cache_class = klass
 
37
        end
 
38
 
 
39
        def terminus_class=(klass)
 
40
            indirection.terminus_class = klass
 
41
        end
 
42
         
 
43
        # Expire any cached instance.
 
44
        def expire(*args)
 
45
            indirection.expire *args
 
46
        end
 
47
         
 
48
        def find(*args)
 
49
            indirection.find *args
 
50
        end
 
51
 
 
52
        def destroy(*args)
 
53
            indirection.destroy *args
 
54
        end
 
55
 
 
56
        def search(*args)
 
57
            indirection.search *args
 
58
        end
 
59
    end
 
60
 
 
61
    module InstanceMethods
 
62
        def save(*args)
 
63
            self.class.indirection.save self, *args
 
64
        end
 
65
    end
 
66
end