module Paths
module methods for handling paths
Public Instance Methods
join(*paths)
click to toggle source
join an Enumerable of paths by normalising slashes on each of the segments, then joining them
# File lib/albacore/paths.rb, line 44 def join *paths raise ArgumentError, 'no paths given' if paths.nil? joined = paths[1..-1].inject(PathnameWrap.new(normalise_slashes(paths[0]))) do |s, t| s + normalise_slashes(t) end PathnameWrap.new joined end
join_str(*paths)
click to toggle source
join an Enumerable of paths by normalising slashes on each of the segments, then joining them, returning a string
# File lib/albacore/paths.rb, line 56 def join_str *paths join(*paths).to_s end
make_command(executable, parameters)
click to toggle source
make a single string-command from a given executable string, by quoting each parameter individually. You can also use Albacore::CrossPlatformCmd#system
given an array of 'stringly' things.
# File lib/albacore/paths.rb, line 27 def make_command executable, parameters raise ArgumentError, "executable is nil" if executable.nil? params = parameters.collect{|p| '"' + p + '"'}.join ' ' exe = normalise_slashes executable %Q{"#{exe}" #{params}} end
normalise(executable, parameters)
click to toggle source
normalise slashes in an executable/parameters combo
# File lib/albacore/paths.rb, line 35 def normalise executable, parameters raise ArgumentError, "executable is nil" if executable.nil? parameters = parameters.collect{ |p| (p === String) ? p : p.to_s } exe = normalise_slashes executable ["#{exe}", parameters] end
normalise_slashes(path)
click to toggle source
normalize the slashes of the path to what the operating system prefers
# File lib/albacore/paths.rb, line 18 def normalise_slashes path return path unless path.respond_to? :gsub raise ArgumentError, "path is nil" if path.nil? ::Rake::Win32.windows? ? path.gsub('/', '\\') : path.gsub('\\', '/') end
separator()
click to toggle source
returns the operating system separator character as a string
# File lib/albacore/paths.rb, line 13 def separator ::Albacore.windows? ? '\\' : '/' end