class Propshaft::Asset
Attributes
logical_path[R]
path[R]
version[R]
Public Class Methods
new(path, logical_path:, version: nil)
click to toggle source
# File lib/propshaft/asset.rb, line 7 def initialize(path, logical_path:, version: nil) @path, @logical_path, @version = path, Pathname.new(logical_path), version end
Public Instance Methods
==(other_asset)
click to toggle source
# File lib/propshaft/asset.rb, line 39 def ==(other_asset) logical_path.hash == other_asset.logical_path.hash end
content()
click to toggle source
# File lib/propshaft/asset.rb, line 11 def content File.binread(path) end
content_type()
click to toggle source
# File lib/propshaft/asset.rb, line 15 def content_type Mime::Type.lookup_by_extension(logical_path.extname.from(1)) end
digest()
click to toggle source
# File lib/propshaft/asset.rb, line 23 def digest @digest ||= Digest::SHA1.hexdigest("#{content}#{version}") end
digested_path()
click to toggle source
# File lib/propshaft/asset.rb, line 27 def digested_path if already_digested? logical_path else logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } end end
fresh?(digest)
click to toggle source
# File lib/propshaft/asset.rb, line 35 def fresh?(digest) self.digest == digest || already_digested? end
length()
click to toggle source
# File lib/propshaft/asset.rb, line 19 def length content.size end
Private Instance Methods
already_digested?()
click to toggle source
# File lib/propshaft/asset.rb, line 44 def already_digested? logical_path.to_s =~ /-([0-9a-zA-Z]{7,128})\.digested/ end