Class: Propshaft::Asset
- Inherits:
-
Object
- Object
- Propshaft::Asset
- Defined in:
- lib/propshaft/asset.rb
Instance Attribute Summary collapse
-
#load_path ⇒ Object
readonly
Returns the value of attribute load_path.
-
#logical_path ⇒ Object
readonly
Returns the value of attribute logical_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other_asset) ⇒ Object
- #content ⇒ Object
- #content_type ⇒ Object
- #digest ⇒ Object
- #digested_path ⇒ Object
- #fresh?(digest) ⇒ Boolean
-
#initialize(path, logical_path:, load_path:) ⇒ Asset
constructor
A new instance of Asset.
- #length ⇒ Object
Constructor Details
#initialize(path, logical_path:, load_path:) ⇒ Asset
Returns a new instance of Asset.
7 8 9 |
# File 'lib/propshaft/asset.rb', line 7 def initialize(path, logical_path:, load_path:) @path, @logical_path, @load_path = path, Pathname.new(logical_path), load_path end |
Instance Attribute Details
#load_path ⇒ Object (readonly)
Returns the value of attribute load_path.
5 6 7 |
# File 'lib/propshaft/asset.rb', line 5 def load_path @load_path end |
#logical_path ⇒ Object (readonly)
Returns the value of attribute logical_path.
5 6 7 |
# File 'lib/propshaft/asset.rb', line 5 def logical_path @logical_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/propshaft/asset.rb', line 5 def path @path end |
Instance Method Details
#==(other_asset) ⇒ Object
39 40 41 |
# File 'lib/propshaft/asset.rb', line 39 def ==(other_asset) logical_path.hash == other_asset.logical_path.hash end |
#content ⇒ Object
11 12 13 |
# File 'lib/propshaft/asset.rb', line 11 def content File.binread(path) end |
#content_type ⇒ Object
15 16 17 |
# File 'lib/propshaft/asset.rb', line 15 def content_type Mime::Type.lookup_by_extension(logical_path.extname.from(1)) end |
#digest ⇒ Object
23 24 25 |
# File 'lib/propshaft/asset.rb', line 23 def digest @digest ||= Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8) end |
#digested_path ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/propshaft/asset.rb', line 27 def digested_path if already_digested? logical_path else logical_path.sub(/\.(\w+(\.map)?)$/) { |ext| "-#{digest}#{ext}" } end end |
#fresh?(digest) ⇒ Boolean
35 36 37 |
# File 'lib/propshaft/asset.rb', line 35 def fresh?(digest) self.digest == digest || already_digested? end |
#length ⇒ Object
19 20 21 |
# File 'lib/propshaft/asset.rb', line 19 def length content.size end |