Class: DictCache::Cache
- Inherits:
-
Object
- Object
- DictCache::Cache
- Defined in:
- lib/dict_cache/cache.rb
Class Method Summary collapse
Class Method Details
.clear ⇒ Object
15 16 17 |
# File 'lib/dict_cache/cache.rb', line 15 def clear `rm -rf #{cache_folder}/*` end |
.date_cache(date = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/dict_cache/cache.rb', line 4 def date_cache(date=nil) @date = date file = [cache_folder, cache_file].join('/') if File.exist? file puts File.read(file) else warn "No cache at date: #{@date}" exit 1 end end |
.with_cache ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dict_cache/cache.rb', line 19 def with_cache folder = cache_folder tty_file = [folder, tty_buffer].join('/') $stdout = File.new(tty_file, 'w') yield $stdout.flush $stdout = STDOUT translate_text = File.read(tty_file) puts translate_text file = [folder, cache_file].join('/') File.open(file, 'a') { |f| f.puts translate_text + "\n" } end |