Sha256: 8517c42281e7f85073398813f4efe7fc91971b6df100ee95697984feb79b9bd5

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

module AsProject

  ##########################
  # Custom Errors
  class ProjectError < StandardError; end
  class UsageError < ProjectError; end
  class BuildError < StandardError; end
end

RAND_CHARS = ['A','B','C','D','E','F','a','b','c','d','e','f']

def AsProject::windowize_cygwin_path2(name)
  expr = /\/cygdrive\/([a-z]|[A-Z])/
  matched = name.match(expr)
  if(matched)
    prefix = matched.captures[0].upcase + ':'
    name.gsub!(expr, prefix)
  end
  name = name.split('/').join('\\')
  return name
end

def Dir::unique_tmpdir(application='RubyApplication')
  rand_max = RAND_CHARS.size
  uniqueish_name = ''
  24.times{ uniqueish_name << RAND_CHARS[rand(rand_max)] }
  
  tmp = Dir.tmpdir
  app_tmp = File.join(tmp, application)
  if(!File.exists?(app_tmp))
    Dir.mkdir(app_tmp)
  end

  tmp = File.expand_path(File.join(app_tmp, uniqueish_name))
  if(File.exists?(tmp) && is_retry)
    raise ProjectError.new('Dir.unique_tmpdir attempted to create a new dir over an existing dir')
#  else if(File.exists?(tmp))
    # Try again once before failing, uniqueish names aren't too unique... 
#    Dir.unique_tmpdir(application, true)
  end
  Dir.mkdir(tmp)
  return tmp
end

def Dir::tmpdir
  tmp = nil
  for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
              ENV['USERPROFILE'], '/tmp']
    if dir and File.directory?(dir) and File.writable?(dir)
      tmp = dir
      break
    end
  end
  if(tmp.nil?)
    raise ProjectError.new('AsProject was unable to find a valid temporary directory on this computer.')
  end
  # Has to actually CD to the dir, because
  # on os x, tmp == /tmp until you're in it,
  # then it's /private/tmp?!
  # TestCases are relying on this value to 
  # Be identical when you retrieve it and
  # when you are 'in' it...
  start = Dir.pwd
  Dir.chdir(tmp)
  tmp = Dir.pwd
  Dir.chdir(start)
  return tmp
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
asproject-0.1.31 lib/asproject_utils.rb
asproject-0.1.33 lib/asproject_utils.rb
asproject-0.1.32 lib/asproject_utils.rb