Class: Dokkit::Cache
- Inherits:
-
Object
- Object
- Dokkit::Cache
- Defined in:
- lib/dokkit/cache/cache.rb
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#cache_filename ⇒ Object
readonly
Returns the value of attribute cache_filename.
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
Instance Method Summary collapse
- #add_dependency(source_fn, format, dep) ⇒ Object
- #clean ⇒ Object
-
#initialize(cache_filename = 'deps.yaml', cache_dir = '.cache') ⇒ Cache
constructor
A new instance of Cache.
- #load ⇒ Object
- #save ⇒ Object
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_dir ⇒ Object (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_filename ⇒ Object (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 |
#deps ⇒ Object (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 |
#clean ⇒ Object
42 43 44 |
# File 'lib/dokkit/cache/cache.rb', line 42 def clean @deps.clear end |
#load ⇒ Object
34 35 36 |
# File 'lib/dokkit/cache/cache.rb', line 34 def load @deps = load_from_yaml || { } end |
#save ⇒ Object
38 39 40 |
# File 'lib/dokkit/cache/cache.rb', line 38 def save write_cache_to_file unless @deps.empty? end |