Method: Chef::ChefFS::PathUtils.join
- Defined in:
- lib/chef/chef_fs/path_utils.rb
.join(*parts) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/chef_fs/path_utils.rb', line 45 def self.join(*parts) return "" if parts.length == 0 # Determine if it started with a slash absolute = parts[0].length == 0 || parts[0].length > 0 && parts[0] =~ /^#{REGEXP_PATH_SEPARATOR}/ # Remove leading and trailing slashes from each part so that the join will work (and the slash at the end will go away) parts = parts.map { |part| part.gsub(/^#{REGEXP_PATH_SEPARATOR}+|#{REGEXP_PATH_SEPARATOR}+$/, "") } # Don't join empty bits result = parts.select { |part| part != "" }.join("/") # Put the / back on absolute ? "/#{result}" : result end |