Module: Paths

Extended by:
Paths
Included in:
Albacore::Paths, Paths
Defined in:
lib/albacore/paths.rb

Overview

module methods for handling paths

Defined Under Namespace

Classes: PathnameWrap

Instance Method Summary collapse

Instance Method Details

#join(*paths) ⇒ Object

join an Enumerable of paths by normalising slashes on each of the segments, then joining them

Raises:

  • (ArgumentError)


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.

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

#separatorObject

returns the operating system separator character as a string



14
15
16
# File 'lib/albacore/paths.rb', line 14

def separator
  ::Albacore.windows? ? '\\' : '/'
end