Class: Divergence::CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/divergence/cache_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(cache_path, cache_num) ⇒ CacheManager

Returns a new instance of CacheManager.



3
4
5
6
7
8
9
10
# File 'lib/divergence/cache_manager.rb', line 3

def initialize(cache_path, cache_num)
  @cache_path = cache_path
  @cache_num = cache_num

  Dir.chdir @cache_path do
    @cached_branches = Dir['*/'].map {|dir| dir.gsub('/', '')}
  end
end

Instance Method Details

#add(branch, src_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/divergence/cache_manager.rb', line 16

def add(branch, src_path)
  Application.log.info "Caching: #{branch} from #{src_path}"

  prune_cache!

  Application.config.callback :before_cache, src_path, :branch => branch

  FileUtils.mkdir_p path(branch)
  sync branch, src_path
  @cached_branches.push branch

  Application.config.callback :after_cache, path(branch), :branch => branch
end

#is_cached?(branch) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/divergence/cache_manager.rb', line 12

def is_cached?(branch)
  @cached_branches.include?(branch)
end

#path(branch) ⇒ Object



34
35
36
# File 'lib/divergence/cache_manager.rb', line 34

def path(branch)
  "#{@cache_path}/#{branch}"
end

#sync(branch, src_path) ⇒ Object



30
31
32
# File 'lib/divergence/cache_manager.rb', line 30

def sync(branch, src_path)
  `rsync -a --delete #{src_path}/* #{path(branch)}`
end