summaryrefslogtreecommitdiffstats
path: root/lib/puppet/file_collection.rb
blob: 7db2600c0d80ea9ef436bbf2e7c14b4deeca6e77 (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
# A simple way to turn file names into singletons,
# so we don't have tons of copies of each file path around.
class Puppet::FileCollection
    require 'puppet/file_collection/lookup'

    def self.collection
        @collection
    end

    def initialize
        @paths = []
        @inverse = {}
    end

    def index(path)
        if i = @inverse[path]
            return i
        else
            @paths << path
            i = @inverse[path] = @paths.length - 1
            return i
        end
    end

    def path(index)
        @paths[index]
    end

    @collection = self.new
end