diff options
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/file_collection.rb | 20 | ||||
| -rw-r--r-- | lib/puppet/file_collection/lookup.rb | 16 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb new file mode 100644 index 000000000..451b496a1 --- /dev/null +++ b/lib/puppet/file_collection.rb @@ -0,0 +1,20 @@ +# 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 + def initialize + @paths = [] + end + + def index(path) + if @paths.include?(path) + return @paths.index(path) + else + @paths << path + return @paths.length - 1 + end + end + + def path(index) + @paths[index] + end +end diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb new file mode 100644 index 000000000..8f69c6681 --- /dev/null +++ b/lib/puppet/file_collection/lookup.rb @@ -0,0 +1,16 @@ +require 'puppet/file_collection' + +# A simple module for looking up file paths and indexes +# in a file collection. +module Puppet::FileCollection::Lookup + attr_accessor :line, :file_index + + def file=(path) + @file_index = file_collection.index(path) + end + + def file + return nil unless file_index + file_collection.path(file_index) + end +end |
