Class: Puppet::FileCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/file_collection.rb

Overview

A simple way to turn file names into singletons, so we don’t have tons of copies of each file path around.

Defined Under Namespace

Modules: Lookup

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileCollection

Returns a new instance of FileCollection.



10
11
12
13
# File 'lib/puppet/file_collection.rb', line 10

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

Class Method Details

.collectionObject



6
7
8
# File 'lib/puppet/file_collection.rb', line 6

def self.collection
  @collection
end

Instance Method Details

#index(path) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/puppet/file_collection.rb', line 15

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

#path(index) ⇒ Object



25
26
27
# File 'lib/puppet/file_collection.rb', line 25

def path(index)
  @paths[index]
end