class Propshaft::Asset
Attributes
Public Class Methods
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
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
Source
# File lib/propshaft/asset.rb, line 48 def ==(other_asset) logical_path.hash == other_asset.logical_path.hash end
Source
# File lib/propshaft/asset.rb, line 20 def content(encoding: "ASCII-8BIT") File.read(path, encoding: encoding) end
Source
# File lib/propshaft/asset.rb, line 24 def content_type Mime::Type.lookup_by_extension(logical_path.extname.from(1)) end
Source
# File lib/propshaft/asset.rb, line 32 def digest @digest ||= Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8) end
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
Source
# File lib/propshaft/asset.rb, line 44 def fresh?(digest) self.digest == digest || already_digested? end
Private Instance Methods
Source
# File lib/propshaft/asset.rb, line 57 def already_digested? logical_path.to_s =~ /-([0-9a-zA-Z_-]{7,128})\.digested/ end
Source
# File lib/propshaft/asset.rb, line 53 def content_with_compile_references content + load_path.find_referenced_by(self).collect(&:content).join end