]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/inifile/lib/puppet/util/external_iterator.rb
add puppetlabs/inifile to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / inifile / lib / puppet / util / external_iterator.rb
diff --git a/3rdparty/modules/inifile/lib/puppet/util/external_iterator.rb b/3rdparty/modules/inifile/lib/puppet/util/external_iterator.rb
new file mode 100644 (file)
index 0000000..45c0fa4
--- /dev/null
@@ -0,0 +1,28 @@
+module Puppet
+module Util
+  class ExternalIterator
+    def initialize(coll)
+      @coll = coll
+      @cur_index = -1
+    end
+
+    def next
+      @cur_index = @cur_index + 1
+      item_at(@cur_index)
+    end
+
+    def peek
+      item_at(@cur_index + 1)
+    end
+
+    private
+    def item_at(index)
+      if @coll.length > index
+        [@coll[index], index]
+      else
+        [nil, nil]
+      end
+    end
+  end
+end
+end