Class: Spritely::Cache
- Inherits:
-
Struct
- Object
- Struct
- Spritely::Cache
- Defined in:
- lib/spritely/cache.rb
Constant Summary collapse
- PNG_SIGNATURE_LENGTH =
8
- PNG_INFO_LENGTH =
8
- PNG_CRC_LENGTH =
Cyclic Redundancy Check (CRC) byte-length; www.w3.org/TR/PNG/#5Chunk-layout
4
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename
4 5 6 |
# File 'lib/spritely/cache.rb', line 4 def filename @filename end |
Class Method Details
.busted?(filename, expected_cache_key) ⇒ Boolean
13 14 15 |
# File 'lib/spritely/cache.rb', line 13 def self.busted?(filename, expected_cache_key) new(filename).key != expected_cache_key end |
.generate(*objects) ⇒ Object
9 10 11 |
# File 'lib/spritely/cache.rb', line 9 def self.generate(*objects) Digest::MD5.hexdigest(objects.collect(&:cache_key).join) end |
Instance Method Details
#key ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spritely/cache.rb', line 17 def key return @key if @key File.open(filename) do |file| file.read(PNG_SIGNATURE_LENGTH) # we first have to read the signature to fast-forward the IO#pos until file.eof? each_chunk(file) do |keyword, value| if keyword == 'cache_key' return @key = value break end end end end end |