Module: Vedeu::Output::CompressorCache Private
- Extended by:
- CompressorCache, Repositories::Storage
- Included in:
- CompressorCache
- Defined in:
- lib/vedeu/output/compressor_cache.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Store a copy of the data last processed by Compressor. Both the original content and the compressed versions are kept (unless modified) to speed up the rendering of the display.
Instance Method Summary collapse
- #cache(content, compression = false) ⇒ String private
- #cached?(content) ⇒ Boolean private private
- #compress(content) ⇒ String private private
- #empty?(content) ⇒ Boolean private private
- #in_memory ⇒ Hash<Symbol => Array<void>, String> private private
- #read(key) ⇒ Array<void> private private
- #same?(content) ⇒ Boolean private private
- #size?(content) ⇒ Boolean private private
- #uncompress(content) ⇒ String private private
- #write(content, compression) ⇒ Hash<Symbol => Array<void>> private private
Methods included from Repositories::Storage
Instance Method Details
#cache(content, compression = false) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 |
# File 'lib/vedeu/output/compressor_cache.rb', line 22 def cache(content, compression = false) write(content, compression) unless empty?(content) || cached?(content) compression ? read(:compress) : read(:uncompress) end |
#cached?(content) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/vedeu/output/compressor_cache.rb', line 32 def cached?(content) size?(content) && same?(content) end |
#compress(content) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/vedeu/output/compressor_cache.rb', line 50 def compress(content) Vedeu::Output::Compressors::Character.with(content) end |
#empty?(content) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/vedeu/output/compressor_cache.rb', line 56 def empty?(content) content.nil? || content.empty? end |
#in_memory ⇒ Hash<Symbol => Array<void>, String> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 65 66 67 |
# File 'lib/vedeu/output/compressor_cache.rb', line 61 def in_memory { compress: '', original: [], uncompress: '', } end |
#read(key) ⇒ Array<void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/vedeu/output/compressor_cache.rb', line 71 def read(key) storage.fetch(key, []) end |
#same?(content) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/vedeu/output/compressor_cache.rb', line 44 def same?(content) content == read(:original) end |
#size?(content) ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/vedeu/output/compressor_cache.rb', line 38 def size?(content) content.size == read(:original).size end |
#uncompress(content) ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/vedeu/output/compressor_cache.rb', line 77 def uncompress(content) Vedeu::Output::Compressors::Simple.with(content) end |
#write(content, compression) ⇒ Hash<Symbol => Array<void>> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/output/compressor_cache.rb', line 84 def write(content, compression) storage[:original] = content if compression storage[:compress] = compress(content) else storage[:uncompress] = uncompress(content) end end |