class Propshaft::Asset

Attributes

load_path[R]
logical_path[R]
path[R]

Public Class Methods

extract_path_and_digest(digested_path) click to toggle source
# File lib/propshaft/asset.rb, line 8
def extract_path_and_digest(digested_path)
  digest = digested_path[/-([0-9a-zA-Z]{7,128})\.(?!digested)([^.]|.map)+\z/, 1]
  path   = digest ? digested_path.sub("-#{digest}", "") : digested_path

  [path, digest]
end
new(path, logical_path:, load_path:) click to toggle source
# File lib/propshaft/asset.rb, line 16
def initialize(path, logical_path:, load_path:)
  @path, @logical_path, @load_path = path, Pathname.new(logical_path), load_path
end

Public Instance Methods

==(other_asset) click to toggle source
# File lib/propshaft/asset.rb, line 48
def ==(other_asset)
  logical_path.hash == other_asset.logical_path.hash
end
content(encoding: "ASCII-8BIT") click to toggle source
# File lib/propshaft/asset.rb, line 20
def content(encoding: "ASCII-8BIT")
  File.read(path, encoding: encoding)
end
content_type() click to toggle source
# File lib/propshaft/asset.rb, line 24
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 32
def digest
  @digest ||= Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8)
end
digested_path() click to toggle source
# File lib/propshaft/asset.rb, line 36
def digested_path
  if already_digested?
    logical_path
  else
    logical_path.sub(/\.(\w+(\.map)?)$/) { |ext| "-#{digest}#{ext}" }
  end
end
fresh?(digest) click to toggle source
# File lib/propshaft/asset.rb, line 44
def fresh?(digest)
  self.digest == digest || already_digested?
end
length() click to toggle source
# File lib/propshaft/asset.rb, line 28
def length
  content.size
end

Private Instance Methods

already_digested?() click to toggle source
# File lib/propshaft/asset.rb, line 57
def already_digested?
  logical_path.to_s =~ /-([0-9a-zA-Z_-]{7,128})\.digested/
end
content_with_compile_references() click to toggle source
# File lib/propshaft/asset.rb, line 53
def content_with_compile_references
  content + load_path.find_referenced_by(self).collect(&:content).join
end