lib/propshaft/asset.rb in propshaft-0.6.4 vs lib/propshaft/asset.rb in propshaft-0.7.0

- old
+ new

@@ -1,13 +1,18 @@ require "digest/sha1" require "action_dispatch/http/mime_type" class Propshaft::Asset + PREDIGESTED_REGEX = /-([0-9a-zA-Z]{7,128}\.digested)/ + attr_reader :path, :logical_path, :version def initialize(path, logical_path:, version: nil) - @path, @logical_path, @version = path, Pathname.new(logical_path), version + @path = path + @digest = logical_path.to_s[PREDIGESTED_REGEX, 1] + @logical_path = Pathname.new(@digest ? logical_path.sub("-#{@digest}", "") : logical_path) + @version = version end def content File.binread(path) end @@ -23,25 +28,16 @@ def digest @digest ||= Digest::SHA1.hexdigest("#{content}#{version}") end def digested_path - if already_digested? - logical_path - else - logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } - end + logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" } end def fresh?(digest) - self.digest == digest || already_digested? + self.digest == digest end def ==(other_asset) logical_path.hash == other_asset.logical_path.hash end - - private - def already_digested? - logical_path.to_s =~ /-([0-9a-zA-Z]{7,128})\.digested/ - end end