Class: Gin::AssetManifest::Asset
- Inherits:
-
Object
- Object
- Gin::AssetManifest::Asset
- Defined in:
- lib/gin/asset_manifest.rb
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#target_file ⇒ Object
Returns the value of attribute target_file.
Instance Method Summary collapse
-
#initialize(path, opts = {}) ⇒ Asset
constructor
A new instance of Asset.
- #outdated? ⇒ Boolean
- #to_hash ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(path, opts = {}) ⇒ Asset
Returns a new instance of Asset.
11 12 13 14 15 16 17 18 |
# File 'lib/gin/asset_manifest.rb', line 11 def initialize path, opts={} @path = path @rtime = opts[:rtime] || Time.now @mtime = opts[:mtime] || File.mtime(path) @digest = opts[:digest] || Digest::MD5.file(path).hexdigest @target_file = opts[:target_file] @dependencies = opts[:dependencies] || [] end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
8 9 10 |
# File 'lib/gin/asset_manifest.rb', line 8 def dependencies @dependencies end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
8 9 10 |
# File 'lib/gin/asset_manifest.rb', line 8 def digest @digest end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
8 9 10 |
# File 'lib/gin/asset_manifest.rb', line 8 def mtime @mtime end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/gin/asset_manifest.rb', line 8 def path @path end |
#target_file ⇒ Object
Returns the value of attribute target_file.
9 10 11 |
# File 'lib/gin/asset_manifest.rb', line 9 def target_file @target_file end |
Instance Method Details
#outdated? ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/gin/asset_manifest.rb', line 29 def outdated? return true if !File.file?(@path) return true if @target_file && !File.file?(@target_file) return @mtime != File.mtime(@path) if @rtime - @mtime > 0 @digest != Digest::MD5.file(@path).hexdigest end |
#to_hash ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gin/asset_manifest.rb', line 37 def to_hash hash = { :target_file => @target_file, :rtime => @rtime, :mtime => @mtime, :digest => @digest } hash[:dependencies] = @dependencies.dup unless @dependencies.empty? hash end |
#update! ⇒ Object
21 22 23 24 25 26 |
# File 'lib/gin/asset_manifest.rb', line 21 def update! return unless File.file?(@path) @rtime = Time.now @mtime = File.mtime(@path) @digest = Digest::MD5.file(@path).hexdigest end |