lib/dassets/asset_file.rb in dassets-0.14.5 vs lib/dassets/asset_file.rb in dassets-0.15.0
- old
+ new
@@ -1,36 +1,39 @@
-require 'rack/utils'
-require 'rack/mime'
-require 'dassets/source_proxy'
+# frozen_string_literal: true
+require "dassets/source_proxy"
+require "rack/utils"
+require "rack/mime"
+
module Dassets; end
class Dassets::AssetFile
-
attr_reader :digest_path, :dirname, :extname, :basename, :source_proxy
def initialize(digest_path)
@digest_path = digest_path
@dirname = File.dirname(@digest_path)
@extname = File.extname(@digest_path)
@basename = File.basename(@digest_path, @extname)
- @source_proxy = Dassets::SourceProxy.new(@digest_path, {
- :content_cache => Dassets.config.content_cache,
- :fingerprint_cache => Dassets.config.fingerprint_cache
- })
+ @source_proxy =
+ Dassets::SourceProxy.new(
+ @digest_path,
+ content_cache: Dassets.config.content_cache,
+ fingerprint_cache: Dassets.config.fingerprint_cache,
+ )
end
def digest!
return if !self.exists?
Dassets.config.file_store.save(self.url){ self.content }
end
def url
path_basename = "#{@basename}-#{self.fingerprint}#{@extname}"
- path = File.join(@dirname, path_basename).sub(/^\.\//, '').sub(/^\//, '')
+ path =
+ File.join(@dirname, path_basename).sub(/^\.\//, "").sub(/^\//, "")
"#{dassets_base_url}/#{path}"
end
-
alias_method :href, :url
def fingerprint
return nil if !self.exists?
@source_proxy.fingerprint
@@ -46,11 +49,11 @@
@source_proxy.mtime.httpdate
end
def size
return nil if !self.exists?
- Rack::Utils.bytesize(self.content)
+ self.content.bytesize
end
def mime_type
return nil if !self.exists?
Rack::Mime.mime_type(@extname)
@@ -73,7 +76,6 @@
private
def dassets_base_url
Dassets.config.base_url.to_s
end
-
end