class Pinion::StaticAsset

Public Class Methods

new(virtual_path, real_path) click to toggle source
# 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

Public Instance Methods

contents() click to toggle source

Don’t cache (possibly large) static files in memory

# File lib/pinion/static_asset.rb, line 20
def contents() File.read(@real_path) end
invalidate() click to toggle source
# File lib/pinion/static_asset.rb, line 24
def invalidate
  Asset.cached_assets.delete(@virtual_path)
end
latest_mtime() click to toggle source
# File lib/pinion/static_asset.rb, line 22
def latest_mtime() File.stat(@real_path).mtime end