Class: Pinion::StaticAsset
Instance Attribute Summary
Attributes inherited from Asset
#checksum, #extension, #length, #mtime
Instance Method Summary collapse
-
#contents ⇒ Object
Don’t cache (possibly large) static files in memory.
-
#initialize(virtual_path, real_path) ⇒ StaticAsset
constructor
A new instance of StaticAsset.
- #invalidate ⇒ Object
- #latest_mtime ⇒ Object
Methods inherited from Asset
[], #content_type, #each, find_file, find_source_file_and_conversion, find_uncached_asset, static, watch_path
Constructor Details
#initialize(virtual_path, real_path) ⇒ StaticAsset
Returns a new instance of StaticAsset.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pinion/static_asset.rb', line 8 def initialize(virtual_path, real_path) raise Error, "Bad path for static file: '#{real_path}'." unless File.file? real_path @real_path = real_path @virtual_path = virtual_path temp_contents = contents @length = Rack::Utils.bytesize(temp_contents) @mtime = latest_mtime base, dot, @extension = virtual_path.rpartition(".") @checksum = Digest::MD5.hexdigest(temp_contents) end |
Instance Method Details
#contents ⇒ Object
Don’t cache (possibly large) static files in memory
20 |
# File 'lib/pinion/static_asset.rb', line 20 def contents() File.read(@real_path) end |
#invalidate ⇒ Object
24 25 26 |
# File 'lib/pinion/static_asset.rb', line 24 def invalidate Asset.cached_assets.delete(@virtual_path) end |
#latest_mtime ⇒ Object
22 |
# File 'lib/pinion/static_asset.rb', line 22 def latest_mtime() File.stat(@real_path).mtime end |