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.



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

def initialize(url, options = {})
  @cache = options[:cache] || '/tmp/code_cache'
  @url = url
  
  check_repo(url)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



7
8
9
# File 'lib/code_cache/repo.rb', line 7

def cache
  @cache
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/code_cache/repo.rb', line 7

def url
  @url
end

Instance Method Details

#create_cache(revision) ⇒ Object



16
17
18
19
20
# File 'lib/code_cache/repo.rb', line 16

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



23
24
25
26
27
28
29
30
# File 'lib/code_cache/repo.rb', line 23

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



32
33
34
# File 'lib/code_cache/repo.rb', line 32

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