The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:

dirs_between.rb

dirs_between() function, quick and dirty implementation - Thomas Bellman, 08/19/2009 09:38 am

Download (625 Bytes)

 
1
module Puppet::Parser::Functions
2
    newfunction(:dirs_between, :type => :rvalue, :doc => "\
3
        Generate a list of pathnames.  Bla, bla, bla.
4
        ") \
5
    do |args|
6
        if args.length != 2
7
            self.fail("dirs_between(): wrong number of arguments" +
8
                      " (#{args.length} for 2)")
9
        end
10
        topdir = args[0]
11
        subbottom = args[1]
12
        subdirs = []
13
        while subbottom != "."
14
            subbottom, component = File.split(subbottom)
15
            subdirs.unshift(component)
16
        end
17
        dir = topdir
18
        paths = [ dir ]
19
        while subdirs.length > 0
20
            component = subdirs.shift()
21
            dir = File.join(dir, component)
22
            paths.push(dir)
23
        end
24
        return paths
25
    end
26
end