Class: Overapp::TmpDir

Inherits:
Object show all
Defined in:
lib/overapp/util/tmp_dir.rb

Class Method Summary collapse

Class Method Details

.base_dirObject



4
5
6
# File 'lib/overapp/util/tmp_dir.rb', line 4

def base_dir
  File.expand_path(File.dirname(__FILE__) + "/../../../tmp")
end

.local_repo_mapObject



27
28
29
30
31
32
# File 'lib/overapp/util/tmp_dir.rb', line 27

def local_repo_map
  res = {}
  res["https://github.com/mharris717/ember_auth_rails_overlay.git"] = "ember_auth_rails_overlay"
  res["https://github.com/mharris717/widget_overlay_rails.git"] = "rails_widget"
  res
end

.to_local_repo_path(url) ⇒ Object



34
35
36
37
38
# File 'lib/overapp/util/tmp_dir.rb', line 34

def to_local_repo_path(url)
  base = local_repo_map[url]
  raise "no base #{url}" unless base
  "/code/orig/ember_npm_projects/overlays/#{base}"
end

.with(ops = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/overapp/util/tmp_dir.rb', line 7

def with(ops={})
  d = Time.now.strftime("%Y%m%d%H%M%S%L")
  dir = "#{base_dir}/td_#{d}_#{rand(10000000)}"
  `mkdir #{dir}`
  if block_given?
    Dir.chdir(dir) do
      yield dir
    end
  else
    dir
  end
ensure
  if block_given?
    delete = lambda do
      ec "rm -rf #{dir}", :silent => false
    end
    #ObjectSpace.define_finalizer(self, delete)
  end
end

.with_repo_path(url) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/overapp/util/tmp_dir.rb', line 40

def with_repo_path(url)
  url = Overapp.to_proper_dir(url)
  with do |dir|
    `git clone #{url} . 2>&1`
    yield dir
  end
end

.with_repo_path_localuse(url) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/overapp/util/tmp_dir.rb', line 48

def with_repo_path_localuse(url)
  File.create "/code/orig/overapp/repo.txt",url
  dir = to_local_repo_path(url)
  Dir.chdir(dir) do
    yield dir
  end
end