Class: Dokkit::Cache

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_filename = 'deps.yaml', cache_dir = '.cache') ⇒ Cache

Returns a new instance of Cache.



16
17
18
19
20
21
22
# File 'lib/dokkit/cache/cache.rb', line 16

def initialize(cache_filename = 'deps.yaml', cache_dir = '.cache')
  @cache_filename = cache_filename
  @cache_dir = cache_dir
  @complete_cache_filename = File.join(cache_dir, cache_filename)
  load
  at_exit { save }
end

Instance Attribute Details

#cache_dirObject (readonly)

Returns the value of attribute cache_dir.



14
15
16
# File 'lib/dokkit/cache/cache.rb', line 14

def cache_dir
  @cache_dir
end

#cache_filenameObject (readonly)

Returns the value of attribute cache_filename.



14
15
16
# File 'lib/dokkit/cache/cache.rb', line 14

def cache_filename
  @cache_filename
end

#depsObject (readonly)

Returns the value of attribute deps.



14
15
16
# File 'lib/dokkit/cache/cache.rb', line 14

def deps
  @deps
end

Instance Method Details

#add_dependency(source_fn, format, dep) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/dokkit/cache/cache.rb', line 24

def add_dependency(source_fn, format, dep)
  @deps[source_fn] ||= { format => [] }
  if @deps[source_fn][format]
    @deps[source_fn][format] << dep unless (dep.nil? or @deps[source_fn][format].include?(dep))
  else
    @deps[source_fn][format] = []
    @deps[source_fn][format] << dep unless (dep.nil? or @deps[source_fn][format].include?(dep))
  end
end

#cleanObject



42
43
44
# File 'lib/dokkit/cache/cache.rb', line 42

def clean
  @deps.clear
end

#loadObject



34
35
36
# File 'lib/dokkit/cache/cache.rb', line 34

def load
  @deps = load_from_yaml || { }
end

#saveObject



38
39
40
# File 'lib/dokkit/cache/cache.rb', line 38

def save
  write_cache_to_file unless @deps.empty?
end