Module: RepoManager::ActionHelper

Included in:
Add, GitAction, ListAction, StatusAction, ThorHelper
Defined in:
lib/repo_manager/actions/action_helper.rb

Instance Method Summary collapse

Instance Method Details

#relative_path(path) ⇒ Object

@return the relative path from the CWD



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/repo_manager/actions/action_helper.rb', line 22

def relative_path(path)
  return unless path

  path = Pathname.new(File.expand_path(path, FileUtils.pwd))
  cwd = Pathname.new(FileUtils.pwd)

  if windows?
    # c:/home D:/path/here will faile with ArgumentError: different prefix
    return path.to_s if path.to_s.capitalize[0] != cwd.to_s.capitalize[0]
  end

  path = path.relative_path_from(cwd)
  path = "./#{path}" unless path.absolute? || path.to_s.match(/^\./)
  path.to_s
end

#shell_quote(string) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/repo_manager/actions/action_helper.rb', line 8

def shell_quote(string)
  return "" if string.nil? or string.empty?
  if windows?
    %{"#{string}"}
  else
    string.split("'").map{|m| "'#{m}'" }.join("\\'")
  end
end

#windows?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/repo_manager/actions/action_helper.rb', line 17

def windows?
  RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i
end