Class: CodeCache::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/code_cache/repo.rb

Direct Known Subclasses

Git, SVN

Defined Under Namespace

Classes: Git, SVN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Repo

Returns a new instance of Repo.



11
12
13
14
15
16
17
# File 'lib/code_cache/repo.rb', line 11

def initialize(url, options = {})
  cache_dir = Dir.tmpdir() if RbConfig::CONFIG['host_os'].include? "ming" 
  @cache = options[:cache] || cache_dir || '/tmp/code_cache'
  @url = url
  
  check_repo(url)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



9
10
11
# File 'lib/code_cache/repo.rb', line 9

def cache
  @cache
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/code_cache/repo.rb', line 9

def url
  @url
end

Instance Method Details

#create_cache(revision) ⇒ Object



19
20
21
22
23
# File 'lib/code_cache/repo.rb', line 19

def create_cache(revision)
  if !Dir.exist? location_in_cache(revision)
    FileUtils.mkdir_p @cache
  end
end

#location_in_cache(revision = nil) ⇒ Object

Calculates the location of a cached checkout



26
27
28
29
30
31
32
33
# File 'lib/code_cache/repo.rb', line 26

def location_in_cache( revision = nil )
  begin
    elements = [cache, repo_type, split_url, revision].flatten.compact.collect { |i| i.to_s } 
    File.join( elements )
  rescue => e
    raise CacheCalculationError.new(e.msg + e.backtrace.to_s)
  end
end

#repo_typeObject



35
36
37
# File 'lib/code_cache/repo.rb', line 35

def repo_type
  self.class.to_s.split('::').last.downcase
end