Class: Divergence::CacheManager
- Inherits:
-
Object
- Object
- Divergence::CacheManager
- Defined in:
- lib/divergence/cache_manager.rb
Instance Method Summary collapse
- #add(branch, src_path) ⇒ Object
-
#initialize(cache_path, cache_num) ⇒ CacheManager
constructor
A new instance of CacheManager.
- #is_cached?(branch) ⇒ Boolean
- #path(branch) ⇒ Object
- #sync(branch, src_path) ⇒ Object
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
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 |