Class: Dassets::AssetFile
- Inherits:
-
Object
- Object
- Dassets::AssetFile
- Defined in:
- lib/dassets/asset_file.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#digest_path ⇒ Object
readonly
Returns the value of attribute digest_path.
-
#dirname ⇒ Object
readonly
Returns the value of attribute dirname.
-
#extname ⇒ Object
readonly
Returns the value of attribute extname.
-
#source_proxy ⇒ Object
readonly
Returns the value of attribute source_proxy.
Instance Method Summary collapse
- #==(other_asset_file) ⇒ Object
- #content ⇒ Object
- #digest! ⇒ Object
- #exists? ⇒ Boolean
- #fingerprint ⇒ Object
-
#initialize(digest_path) ⇒ AssetFile
constructor
A new instance of AssetFile.
- #mime_type ⇒ Object
- #mtime ⇒ Object
- #response_headers ⇒ Object
- #size ⇒ Object
- #url ⇒ Object (also: #href)
Constructor Details
#initialize(digest_path) ⇒ AssetFile
Returns a new instance of AssetFile.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dassets/asset_file.rb', line 10 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 }) end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
8 9 10 |
# File 'lib/dassets/asset_file.rb', line 8 def basename @basename end |
#digest_path ⇒ Object (readonly)
Returns the value of attribute digest_path.
8 9 10 |
# File 'lib/dassets/asset_file.rb', line 8 def digest_path @digest_path end |
#dirname ⇒ Object (readonly)
Returns the value of attribute dirname.
8 9 10 |
# File 'lib/dassets/asset_file.rb', line 8 def dirname @dirname end |
#extname ⇒ Object (readonly)
Returns the value of attribute extname.
8 9 10 |
# File 'lib/dassets/asset_file.rb', line 8 def extname @extname end |
#source_proxy ⇒ Object (readonly)
Returns the value of attribute source_proxy.
8 9 10 |
# File 'lib/dassets/asset_file.rb', line 8 def source_proxy @source_proxy end |
Instance Method Details
#==(other_asset_file) ⇒ Object
67 68 69 70 71 |
# File 'lib/dassets/asset_file.rb', line 67 def ==(other_asset_file) other_asset_file.kind_of?(Dassets::AssetFile) && self.digest_path == other_asset_file.digest_path && self.fingerprint == other_asset_file.fingerprint end |
#content ⇒ Object
39 40 41 42 |
# File 'lib/dassets/asset_file.rb', line 39 def content return nil if !self.exists? @source_proxy.content end |
#digest! ⇒ Object
21 22 23 24 |
# File 'lib/dassets/asset_file.rb', line 21 def digest! return if !self.exists? Dassets.config.file_store.save(self.url){ self.content } end |
#exists? ⇒ Boolean
63 64 65 |
# File 'lib/dassets/asset_file.rb', line 63 def exists? @source_proxy.exists? end |
#fingerprint ⇒ Object
34 35 36 37 |
# File 'lib/dassets/asset_file.rb', line 34 def fingerprint return nil if !self.exists? @source_proxy.fingerprint end |
#mime_type ⇒ Object
54 55 56 57 |
# File 'lib/dassets/asset_file.rb', line 54 def mime_type return nil if !self.exists? Rack::Mime.mime_type(@extname) end |
#mtime ⇒ Object
44 45 46 47 |
# File 'lib/dassets/asset_file.rb', line 44 def mtime return nil if !self.exists? @source_proxy.mtime.httpdate end |
#response_headers ⇒ Object
59 60 61 |
# File 'lib/dassets/asset_file.rb', line 59 def response_headers @source_proxy.response_headers end |
#size ⇒ Object
49 50 51 52 |
# File 'lib/dassets/asset_file.rb', line 49 def size return nil if !self.exists? Rack::Utils.bytesize(self.content) end |
#url ⇒ Object Also known as: href
26 27 28 29 30 |
# File 'lib/dassets/asset_file.rb', line 26 def url path_basename = "#{@basename}-#{self.fingerprint}#{@extname}" path = File.join(@dirname, path_basename).sub(/^\.\//, '').sub(/^\//, '') "#{dassets_base_url}/#{path}" end |