diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-12 23:42:31 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-02-28 09:16:42 +1100 |
commit | 373d505c381696f880c305a9357a6e50342079b8 (patch) | |
tree | 3cc0662af61f698658e9d65971902fac72e4272d /lib/puppet | |
parent | 0e467869f4d427a8c42e1c2ff6a0bb215f288b09 (diff) | |
download | puppet-373d505c381696f880c305a9357a6e50342079b8.tar.gz puppet-373d505c381696f880c305a9357a6e50342079b8.tar.xz puppet-373d505c381696f880c305a9357a6e50342079b8.zip |
Adding a FileCollection and a lookup module for it.
Signed-off-by: Luke Kanies <luke@madstop.com>
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 |