summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/collection.rb
blob: e3afbbd8fa9f0c8c8056bd93352a04e5a35ea151 (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
require 'puppet/rails'

class Puppet::Parser::AST
    # An object that collects stored objects from the central cache and returns
    # them to the current host, yo.
    class Collection < AST::Branch
        attr_accessor :type

        def evaluate(hash)
            scope = hash[:scope]

            type = @type.safeevaluate(:scope => scope)

            count = 0
            # Now perform the actual collection, yo.
            Puppet::Rails::RailsObject.find_all_by_collectable(true).each do |obj|
                count += 1
                trans = obj.to_trans

                args = {
                    :name => trans.name,
                    :type => trans.type,
                }

                [:file, :line].each do |param|
                    if val = trans.send(param)
                        args[param] = val
                    end
                end

                args[:arguments] = {}
                trans.each do |p,v|  args[:arguments][p] = v end

                # XXX Because the scopes don't expect objects to return values,
                # we have to manually add our objects to the scope.  This is
                # uber-lame.
                scope.setobject(args)
            end

            scope.debug("Collected %s objects of type %s" %
                [count, type])

            # The return value is entirely ignored right now, unfortunately.
            return nil
        end
    end
end

# $Id$