Class: Courseware::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/courseware/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Cache

Returns a new instance of Cache.



4
5
6
7
8
9
10
11
# File 'lib/courseware/cache.rb', line 4

def initialize(config)
  @config = config

  unless @config[:nocache]
    clone
    update
  end
end

Instance Method Details

#clearObject



26
27
28
# File 'lib/courseware/cache.rb', line 26

def clear
  FileUtils.rm_rf @config[:cachedir]
end

#cloneObject



13
14
15
16
17
18
# File 'lib/courseware/cache.rb', line 13

def clone
  templates = File.join(@config[:cachedir], 'templates')

  FileUtils.mkdir_p(@config[:cachedir]) unless File.exists? @config[:cachedir]
  system('git', 'clone', @config[:templates], templates) unless File.exists? templates
end

#updateObject



20
21
22
23
24
# File 'lib/courseware/cache.rb', line 20

def update
  $logger.debug "Updating template cache..."
  git('templates', 'pull', '--quiet', 'origin', 'master')
  git('templates', 'reset', '--quiet', '--hard', 'HEAD')
end