Module: Paths
Overview
module methods for handling paths
Defined Under Namespace
Classes: PathnameWrap
Instance Method Summary collapse
-
#join(*paths) ⇒ Object
join an Enumerable of paths by normalising slashes on each of the segments, then joining them.
-
#join_str(*paths) ⇒ Object
join an Enumerable of paths by normalising slashes on each of the segments, then joining them, returning a string.
-
#make_command(executable, parameters) ⇒ Object
make a single string-command from a given executable string, by quoting each parameter individually.
-
#normalise(executable, parameters) ⇒ Object
normalise slashes in an executable/parameters combo.
-
#normalise_slashes(path) ⇒ Object
normalize the slashes of the path to what the operating system prefers.
-
#separator ⇒ Object
returns the operating system separator character as a string.
Instance Method Details
#join(*paths) ⇒ Object
join an Enumerable of paths by normalising slashes on each of the segments, then joining them
45 46 47 48 49 50 51 52 53 |
# File 'lib/albacore/paths.rb', line 45 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) ⇒ Object
join an Enumerable of paths by normalising slashes on each of the segments, then joining them, returning a string
57 58 59 |
# File 'lib/albacore/paths.rb', line 57 def join_str *paths join(*paths).to_s end |
#make_command(executable, parameters) ⇒ Object
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.
28 29 30 31 32 33 |
# File 'lib/albacore/paths.rb', line 28 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) ⇒ Object
normalise slashes in an executable/parameters combo
36 37 38 39 40 41 |
# File 'lib/albacore/paths.rb', line 36 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) ⇒ Object
normalize the slashes of the path to what the operating system prefers
19 20 21 22 23 |
# File 'lib/albacore/paths.rb', line 19 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 |