]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Adding ability to specifiy range as the index when selecting indices to collect.
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sun, 24 Apr 2011 00:35:49 +0000 (01:35 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sun, 24 Apr 2011 00:35:49 +0000 (01:35 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
collect_indices.rb

index e96c3e9c8f96b16cdbd6a9ce424592e582658459..cd087b9f7c565e080c397cc3b4a7503870d4c713 100644 (file)
@@ -22,8 +22,28 @@ module Puppet::Parser::Functions
       raise(Puppet::ParseError, 'You must provide indices to collect')
     end
 
-    # In Puppet numbers are often string-encoded ...
-    array = indices.collect { |i| array[i.to_i] }.compact
+    indices_list = []
+
+    indices.each do |i|
+      if m = i.match(/^(\d+)\-(\d+)$/)
+        start = m[1].to_i
+        stop  = m[2].to_i
+
+        raise(Puppet::ParseError, 'Stop index in given indices range ' +
+          'is smaller than the start index') if start > stop
+
+        (start .. stop).each { |i| indices_list << i.to_i }
+      else
+        if not i.match(/^\w+$/)
+          raise(Puppet::ParseError, 'Unknown format of given index')
+        end
+
+        # In Puppet numbers are often string-encoded ...
+        indices_list << i.to_i
+      end
+    end
+
+    array = indices_list.collect { |i| array[i] }.compact
 
     return array
   end